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

crouch script not working properly, can anyone help?

Asked by 2 years ago
Edited 2 years ago

Hey, im making a server sided crouching script for my backrooms game, it works, however, the crouching animation wont stop when i stop holding the button, can anyone help?

a part of the local script

us.InputBegan:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.C then
        crouchserver:FireServer("Play")
    end
end)

us.InputEnded:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.C then
        crouchserver:FireServer("Stop")
    end
end)

server script

local rs = game:GetService("ReplicatedStorage")
local event = rs.crouchserver

event.OnServerEvent:Connect(function(player, bool)
    local player = player
    local character = player.Character or player.CharacterAdded:wait()
    local hum = character:FindFirstChild("Humanoid")
    local hmrp = character:FindFirstChild("HumanoidRootPart")
    local animation = Instance.new("Animation")
    animation.AnimationId = "http://www.roblox.com/asset/?id=9264758487"
    local animation2 = hum:LoadAnimation(animation)
    local originalwalkspeed = hum.WalkSpeed

    if bool == "Play" then
        animation2:Play()
        hum.WalkSpeed = 5
    elseif bool == "Stop" then
        animation2:Stop()
        hum.WalkSpeed = originalwalkspeed
    end
end)

Answer this question