Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Redstone in Roblox, Script not Working, Needs to be fixed, nothing happens?

Asked by 7 years ago
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 answer

Log in to vote
2
Answered by 7 years ago

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"


0
@RobloxianDav Also note that the while loop was pointless and infinite (so it'll stop your code there indefinitely), meaning that Line 13 couldn't run. TheDeadlyPanther 2460 — 7y
Ad

Answer this question