|
| 11 Sep 2015 10:31 PM |
Hello! I'm, basically, trying to get a ceiling fan to turn "on" and "off" when clicking a separate brick. I'm trying to achieve this by anchoring and unanchoring the motor and blades attached to the motor, but I've been unable to get the brick I'm using as the "switch" to work. My script is, as follows:
local brick = script.Parent;
local fan = script.Parent.Parent.Parent.Fan.CeilingFan.Part.Anchored;
brick.ClickDetector.MouseClick:connect(function() if fan.Anchored == true then fan.Anchored = false elseif fan.Anchored == false then fan.Anchored = true end end)
Everything is grouped properly and I have checked, double-checked, and re-checked that all of my paths are correct.
Alternatively, is there a better way to achieve this? I'm not sure how to make a brick spin continuously with a script. I also thought of using separate parts and making them alternate between visible and invisible to give the appearance of turning, but I'm not sure if it would be possible to create a continuing loop with a script when the fan is turned "on". and then ending the script when the fan is turned "off".
Any help is appreciated. Thank you! |
|
|
| Report Abuse |
|
|
|
| 11 Sep 2015 10:58 PM |
You put local fan = script.Parent.Parent.Parent.Fan.CeilingFan.Part.Anchored; which gives you a bool value as it is a property
You meant to do this:
local fan = script.Parent.Parent.Parent.Fan.CeilingFan.Part // Remove ".Anchored" |
|
|
| Report Abuse |
|
|
|
| 11 Sep 2015 11:06 PM |
Thank you. I fixed that, but the fan is still unresponsive when I test the switch. My script is now:
local brick = script.Parent;
local fan = script.Parent.Parent.Parent.Fan.CeilingFan.Part;
brick.ClickDetector.MouseClick:connect(function() if fan.Anchored == true then fan.Anchored = false elseif fan.Anchored == false then fan.Anchored = true end end) |
|
|
| Report Abuse |
|
|
|
| 11 Sep 2015 11:08 PM |
local brick = script.Parent;
local fan = brick.Parent.Parent.Fan.CeilingFan.Part;
brick.ClickDetector.MouseClick:connect(function() fan.Anchored = not fan.Anchored end) |
|
|
| Report Abuse |
|
|
|
| 11 Sep 2015 11:13 PM |
| Thank you. I tried your script, but the outcome is the same. I'm just not sure why this isn't working, but then, I'm only a beginner. |
|
|
| Report Abuse |
|
|
|
| 11 Sep 2015 11:15 PM |
I'm not really sure about this but when you say "Parent.Parent.Fan" it may have mistook it for a property of the parent therefore you could try this-
local brick = script.Parent;
local fan = script.Parent.Parent.Parent:FindFirstChild("Fan").CeilingFan.Part;
brick.ClickDetector.MouseClick:connect(function() if fan.Anchored == true then fan.Anchored = false elseif fan.Anchored == false then fan.Anchored = true end end) |
|
|
| Report Abuse |
|
|
|
| 11 Sep 2015 11:18 PM |
| Unfortunately that didn't work, either, but thank you. This might be more trouble than it's worth at this point! |
|
|
| Report Abuse |
|
|
|
| 11 Sep 2015 11:32 PM |
| Well, I feel silly now. I accidentally welded an anchored part to the parts that were meant to be unanchored. My apologies! Thank you all, again, for all of your help. It's working properly now. |
|
|
| Report Abuse |
|
|