You can write your topic however you want, but you need to answer these questions:
- What do you want to achieve? Keep it simple and clear!
trying to script a localscript where a player plays an animation when he is sprinting
- What is the issue? Include screenshots / videos if possible!
while moving and at the same time toggling the run wont change the animation it is when i move again
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
- dunno how to use the run in animate script
- tried using changed() on boolval but i doesnt
- didnt work properly
- tried to use if else but same thing happened
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
-- This is an example Lua code block
-- SpeedScriptRunner | Version 2.2 | Claasgreeneye
--< Services >--
local Players: Players = game:GetService("Players")
local UIS: UserInputService = game:GetService("UserInputService")
--< Constants >--
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid: Humanoid = Character:WaitForChild("Humanoid")
local DefaultWalkingSpeed = Humanoid.WalkSpeed
--< Variables >--
local Speed: number = 20 -- How fast is the sprinting speed?
local Key: Enum.KeyCode = Enum.KeyCode.LeftControl -- Activation Key
local TweenSpeed: number = 0.4 -- How fast does the field of view change?
local Values = Character:FindFirstChild('CharacterValue')
local isRunning = Values.isRunning
local moveMagnitude = Values.movementMagnitude
--< Animations >--
local SS = game.ReplicatedStorage.Animations
local animator = Humanoid.Animator
local runAnim = animator:LoadAnimation(SS.RunAnim)
--< Main Code >--
local function toggleSprint(Input, Processed)
if not Processed then
if Input.UserInputType == Enum.UserInputType.Keyboard and Input.KeyCode == Key then
if isRunning.Value == true then
Humanoid.WalkSpeed = DefaultWalkingSpeed
isRunning.Value = false
else
isRunning.Value = true
Humanoid.WalkSpeed = Speed
end
end
else
return
end
end
UIS.InputBegan:Connect(toggleSprint)
local valueThread = coroutine.create(function()
while true do
wait()
moveMagnitude.Value = Humanoid.MoveDirection.Magnitude
end
end)
coroutine.resume(valueThread)
moveMagnitude.Changed:Connect(function(event)
if event > 0 and isRunning.Value == true then
runAnim:Play()
UIS.InputBegan:Connect(toggleSprint)
else
runAnim:Stop()
end
end)
--< Player Resetting >--
Player.CharacterAdded:Connect(function(Char)
Humanoid = Char:FindFirstChildWhichIsA("Humanoid") or Char:WaitForChild("Humanoid")
end)