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

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

Asked by 3 years ago

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

Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago
--###----------[[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)
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). BenJaminZooey 9 — 3y
0
Oh! Okay gotcha! Ziffixture 6913 — 3y
0
That should do it for ya! Ziffixture 6913 — 3y
0
Idk if I'm doing something wrong, when I stepped on the part, I could still walk while the animation is playing. BenJaminZooey 9 — 3y
Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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)
0
nevermind a mod has got the solution, but it wasn't marked as solved. KadenBloxYT 135 — 3y
0
m this a kill script Pitched_mobile 191 — 3y
0
oh damn i meant humanoid.Speed not health. really sorry KadenBloxYT 135 — 3y

Answer this question