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

unsure as to why else statement is not working?

Asked by 2 years ago
local clickDetector = workspace.button.ClickDetector

local clicked = false

function onClicked(player)
    if not clicked then 
        clicked = true 
if player.Character then
        player.Character:MoveTo(Vector3.new(-11, -1.9, -16.45))
       end
    end
end
else
clicked = false
if player.Character then
        player.Character:MoveTo(Vector3.new(-27.2, 0.5, 15.5))
    end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

i am mindboggled as to why its not working but if anyone can help would be heavily appriciated!

1 answer

Log in to vote
0
Answered by
SuperPuiu 497 Moderation Voter
2 years ago

G'day!

You did a small mistake in the script, so here is the fixed one:

local clickDetector = workspace.button.ClickDetector

local clicked = false

function onClicked(player)
    if not clicked then 
        clicked = true 
        if player.Character then
            player.Character:MoveTo(Vector3.new(-11, -1.9, -16.45))
        end
    else
        clicked = false
        if player.Character then
            player.Character:MoveTo(Vector3.new(-27.2, 0.5, 15.5))
        end
    end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)
Ad

Answer this question