Ad
Log in to vote
0

Shift to sprint problems? (Animations & Cooldown)

Asked by 4 months ago

Hello! I am absolutely terrible with animations, and stuff like that, so I wanted to ask for help!

Here's the problems I am having: - Cooldown behaves weirdly - Animations play even when you don't walk.

Localscript:

local userInput = game:GetService('UserInputService')
local Players = game:GetService("Players")
local tweenService = game:GetService("TweenService")
local db = true

local SprintSpeed = 20
local WalkSpeed = 10

local Event = game:GetService("ReplicatedStorage"):FindFirstChild("Sprint")
local player = Players.LocalPlayer


local function toggleSprint(input, gameProcessed, ending)
    if db or ending == true then
        db = false
        if not gameProcessed then
            if input.UserInputType == Enum.UserInputType.Keyboard then
                local keycode = input.KeyCode
                if keycode == Enum.KeyCode.LeftShift then
                    Event:FireServer()
                    print("fired")
                    if game.Workspace.CurrentCamera.FieldOfView == 70 then
                        tweenService:Create(game.Workspace.CurrentCamera, TweenInfo.new(3, Enum.EasingStyle.Sine), {FieldOfView = 80}):Play()
                    else
                        tweenService:Create(game.Workspace.CurrentCamera, TweenInfo.new(3, Enum.EasingStyle.Sine), {FieldOfView = 70}):Play()
                    end
                end
            end
        end
        wait(3)
        db = true
    end
end

userInput.InputBegan:Connect(toggleSprint, false)
userInput.InputEnded:Connect(toggleSprint, true)

Server:

local tweenService = game:GetService("TweenService")
for i,plr in pairs(game.Players:GetChildren()) do
    if not plr:FindFirstChild("Sprinting") then
        local value = Instance.new("BoolValue")
        value.Name = "Sprinting"
        value.Parent = plr
    end
end
game.Players.PlayerAdded:Connect(function(plr)
    if not plr:FindFirstChild("Sprinting") then
        local value = Instance.new("BoolValue")
        value.Name = "Sprinting"
        value.Parent = plr
    end
end)
local Event = game:GetService("ReplicatedStorage"):FindFirstChild("Sprint")
Event.OnServerEvent:Connect(function(plr)
    print("receieveddddd")
    if plr.Sprinting.Value == false then
        plr.Sprinting.Value = true
        tweenService:Create(plr.Character.Humanoid, TweenInfo.new(3, Enum.EasingStyle.Sine), {WalkSpeed = 20}):Play()
        local animation = Instance.new("Animation")
        animation.AnimationId = "http://www.roblox.com/Asset?ID=animationhidden"

        local animTrack = plr.Character.Humanoid:LoadAnimation(animation)
        animTrack:Play()
    else
        plr.Sprinting.Value = false
        tweenService:Create(plr.Character.Humanoid, TweenInfo.new(3, Enum.EasingStyle.Sine), {WalkSpeed = 10}):Play()
        local animation = Instance.new("Animation")
        animation.AnimationId = "http://www.roblox.com/Asset?ID=animationhidden"

        local animTrack = plr.Character.Humanoid:LoadAnimation(animation)
        animTrack:Play()
    end
end)

Thanks for helping! - Luxxe

0
You know LoadAnimation works on the Client too right? Ziffixture 6785 — 4mo
0
@Ziffixture Yes! I just want it to play on every client. Dr_Luxxe 5 — 4mo
0
It plays on every client regardless lol ElytraIevu 6 — 4mo

Answer this question