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

3 comments

0

You know LoadAnimation works on the Client too right?

0

@Ziffixture Yes! I just want it to play on every client.

0

It plays on every client regardless lol