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

Why wont the lines inside this if statement work?

Asked by 5 years ago

The lines inside 'if workspace.gen1.toolbox.walkto.Touched == true' won't work. The output doesn't give me anything to work with. Does anyone know why this isn't working?

clickDetector.MouseClick:Connect(function()
    local clicked = true
    humanoid.WalkToPoint = workspace.gen1.toolbox.walkto.Position
    if clicked == true then
        if workspace.gen1.toolbox.walkto.Touched == true then
            humanoid.WalkSpeed = 0
            humanoid.JumpPower = 0
            local animTrack = humanoid:LoadAnimation(animation)
            animTrack:Play()
        end
    end
end)

1 answer

Log in to vote
0
Answered by
aazkao 787 Moderation Voter
5 years ago
Edited 5 years ago

Because Touched is an Event, it does not return a boolean, you should connect a function to touched instead

clickDetector.MouseClick:Connect(function()
    local clicked = true
    humanoid.WalkToPoint = workspace.gen1.toolbox.walkto.Position
    if clicked == true then
        workspace.gen1.toolbox.walkto.Touched:Connect(function()
            humanoid.WalkSpeed = 0
            humanoid.JumpPower = 0
            local animTrack = humanoid:LoadAnimation(animation)
            animTrack:Play()
        end)
    end
end)

And also your Clicked Boolean is redundant, as the Touched event will only ever be triggered when you Click the ClickDetector. So there really isnt a need to check for "Clicked" unless you are doing it for debouncing

0
Thank you :) Marty999 82 — 5y
Ad

Answer this question