Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why wont the lines inside this if statement work?

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

✓ Accepted answer

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

1 comment

0

Thank you :)

This discussion is preserved as it was. New answers, comments, and votes are closed.