while wait() do function onTouched(hit) local a = hit:FindFirstChild("Power") if (a==nil)==false then if (a.Value==nil)==false then script.Parent.Power.Value=true else script.Parent.Power.Value=false end end end end script.Parent.touched:connect(onTouched)
This script doesn't work.
Basically in workspace there is a part which is supposed to be like redstone (except in Roblox), if this part contacts another part, it goes to see if it has a bool value called "Power", if it finds a bool value called power it will check it's value, if it's value is true, then the part's own power value will be put onto true, and transmit it to the next part. Please help.
1: ~=
is "does not equal"
2: not
is the same as == false
(and is shorter and less messy
3: a == nil
can be shortened to not a
4: not not a
can be shortened to a
5: That is not how you connect events.
--We don't need no loops. function onTouched(hit) local a = hit:FindFirstChild("Power") if a and a.Value then --Use and to reduce if statements. script.Parent.Power.Value = true else script.Parent.Power.Value = false end --Alternate: script.Parent.Power.Value = (a and a.Value) end script.Parent.Touched:connect(onTouched) --uppercase T in "Touched"