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

How to make my script change the player's walkspeed when stepped on a part?

Hello, so I'm having trouble with a script. I want to make it so that when you step on a part, it will change your walkspeed for a limited time. But when I try it, it doesn't work. Can anyone help me fix it, please?

local Anim = script.Parent.Animation
local debounce = false

h.WalkSpeed = 0

script.Parent.Touched:connect(function(hit)
	
	if hit.Parent:FindFirstChild("Humanoid") and debounce == false then
		debounce = true
		local AnimTrack = hit.Parent.Humanoid:LoadAnimation(Anim)
		AnimTrack:Play()
		
		debounce = true
		
		h.WalkSpeed = 16
	end
end)

2 answers

✓ Accepted answer
--###----------[[VARIABLES]]----------###--
local Part = script.Parent

local Animation = Part.Animation

local Debounce = false



--###----------[[FUNCTIONS]]----------###--
local function OnPartTouched(CharacterLimb)
	if (Debounce) then return end
	---------------
	local Humanoid = CharacterLimb:FindFirstChild("Humanoid")
	if (Humanoid) then
		---------------
		Debounce = true
		---------------
		Humanoid.WalkSpeed = 0
		---------------
		local AnimationTrack = Humanoid.Animator:LoadAnimation(Animation)
		---------------
		AnimationTrack:Play()
		AnimationTrack.Completed:Wait()
		---------------
		Humanoid.WalkSpeed = 16
		---------------
		Debounce = false
	end
end



--###----------[[SETUP]]----------###--
Part.Touched:Connect(OnPartTouched)

4 comments

0

Sorry, but this didn't work for me. What I'm trying to do is that the walkspeed will be 0 when you touch the part, and after my custom animation is done playing, it will be back at 16. (R6 btw).

0

Oh! Okay gotcha!

0

That should do it for ya!

0

Idk if I'm doing something wrong, when I stepped on the part, I could still walk while the animation is playing.

Put this inside a script inside a part!

script.Parent.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid then
humanoid.Health = 0
wait(5) -- how long to wait
humanoid.Health = 16
end
end)

3 comments

0

nevermind a mod has got the solution, but it wasn't marked as solved.

0

m this a kill script

0

oh damn i meant humanoid.Speed not health. really sorry

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