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

[SOLVED]Why is it printing no gate if i am touching the gate? (Tool)

Asked by 6 years ago
Edited 6 years ago

i tried something what is name Gtae that it open's or i will make a script that will activate it but it isn't working? it just print no gate if i touch the gate with my mouse? The Gate is a Union but it's named Gate

script.Parent.Equipped:Connect(function(mouse)
    mouse.Button1Down:Connect(function()
        if mouse.Target and mouse.Target.Parent.Name == "Gate" then
            if mouse.Target.Open == false then
                mouse.Target.Open = true
                wait(3)
            elseif mouse.Target.Open == true then
                mouse.Target.Open = false
                wait(3)
            end
            else print("no gate")
        end
    end)
end)
0
Any output? radusavin366 617 — 6y
0
Yeah no gate MaxDev_BE 55 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

This is a quite easy to fix mistake. Just add a .Name to the end.

script.Parent.Equipped:Connect(function(mouse)
    mouse.Button1Down:Connect(function()
        if mouse.Target.Parent.Name == "Gate" then
            mouse.Target.CFrame = CFrame.new(-2,0,0)
            else print("no gate")
        end
    end)
end)

You are trying to make a object equal to a string.

0
Nope not working MaxDev_BE 55 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

does the target "gate" have a boolvalue "Open" and "Close"? because a union on its own, does not have a boolean that is named Open and close...

right now, the script looks voor Gate.Open, which is not existant so nil, and moves to the elseif. In the elseif it looks for Gate.Close, which is also non-existant == nil, and moves to the else case, ergo "no gate".

What you want is a boolvalue attached to the Gate that toggled to open and close it. It should be named "Open". A different script could in its place check for a value change and move the door accordingly.

Answer this question