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

What's wrong with this speed script?


script.Parent.Touched:connect(function()
	script.Parent:FindFirstChild("Humanoid")
	local h = script.Parent:FindFirstChild("Humanoid")
	h.WalkSpeed = 50
	script.Parent.TouchEnded:connect(function()
		script.Parent:FindFirstChild("Humanoid")
		local h = script.Parent:FindFirstChild("Humanoid")
		h.WalkSpeed = 16
	end)
end)

--]]This script is supposed to make the player's walkspeed 50 when they touched it, and when they got off the brick, it was supposed to reset the walkspeed back to 16, what's wrong here? 

Output says

Workspace.Part.Script:4: attempt to index local 'h' (a nil value)

OR -- I already made this script, waay before the other guy used it in comments

script.Parent.Touched:connect(function()
    script.Parent:FindFirstChild("Humanoid")
    local h = script.Parent:FindFirstChild("Humanoid")
    h.WalkSpeed = 50
end)

 script.Parent.TouchEnded:connect(function()
        script.Parent:FindFirstChild("Humanoid")
        local h = script.Parent:FindFirstChild("Humanoid")
        h.WalkSpeed = 16
  end)

Output says

17:31:48.911 - Workspace.Part.Script:4: attempt to index local 'h' (a nil value)
-- and
17:31:51.887 - Workspace.Part.Script:10: attempt to index local 'h' (a nil value)

1 comment

0

WHY DID SOMEONE DOWNVOTE ME?! What did I DO?!

1 answer

You don't keep one event in another.

script.Parent.Touched:connect(function()
    script.Parent:FindFirstChild("Humanoid")
    local h = script.Parent:FindFirstChild("Humanoid")
    h.WalkSpeed = 50
end)

 script.Parent.TouchEnded:connect(function()
        script.Parent:FindFirstChild("Humanoid")
        local h = script.Parent:FindFirstChild("Humanoid")
        h.WalkSpeed = 16
  end)

1 comment

0

I used this script already, I been coded this befor eyou posted this answer, it just tells me I can't localize 'h' for some reason, I'll updae my post

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