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)
--###----------[[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)
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)