I know this was a long time ago, but I’m continuing my project and need help on one thing about the script, for some reason, when I respawn, it doesn’t let me sprint anymore. Do you know why?
It’s prob using old character reference refresh script should work try add this code
Player.CharacterAdded:Connect(function(newChar)
script.Disabled = true
script.Disabled = false
end)
Btw i still at school so i don’t have time to test it (and i never used code block on mobile before so sorry if the code block didn’t work)
I don’t perfectly understand yet, where would I put it?
Heres the code:
local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
Player.CharacterAdded:Wait()
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")
local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://8707792876"
local Animation = Humanoid:LoadAnimation(Animation)
UIS.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.Gamepad1 then
if input.KeyCode == Enum.KeyCode.ButtonL2 then
if Character.Humanoid.MoveDirection.Magnitude > 0 then
Animation:Play()
Humanoid.WalkSpeed = 28
end
end
elseif input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.LeftShift then
if Character.Humanoid.MoveDirection.Magnitude > 0 then
Animation:Play()
Humanoid.WalkSpeed = 28
end
end
end
end)
UIS.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
Animation:Stop()
Humanoid.WalkSpeed = 18
elseif input.KeyCode == Enum.KeyCode.ButtonL2 then
Animation:Stop()
Humanoid.WalkSpeed = 18
end
end)
Humanoid.Jumping:Connect(function(jumping)
if jumping and Animation.IsPlaying then
Animation:Stop()
Humanoid.WalkSpeed = 18
end
end)
Humanoid.Running:Connect(function(speed)
if speed == 0 and Animation.IsPlaying then
Animation:Stop()
Humanoid.WalkSpeed = 18
end
end)
Also @RandomPlayerOne1 you can take your time.
Below this line will be fine
30c
will I remove the Player.CharacterAdded:Wait()?
Delete this line
And change this variable
To
local Character = Player.Character or Player.CharacterAdded:Wait()
So my code should look like this?:
local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
Player.CharacterAdded:Connect(function(newChar)
script.Disabled = true
script.Disabled = false
end)
local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://8707792876"
local Animation = Humanoid:LoadAnimation(Animation)
UIS.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.Gamepad1 then
if input.KeyCode == Enum.KeyCode.ButtonL2 then
if Character.Humanoid.MoveDirection.Magnitude > 0 then
Animation:Play()
Humanoid.WalkSpeed = 28
end
end
elseif input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.LeftShift then
if Character.Humanoid.MoveDirection.Magnitude > 0 then
Animation:Play()
Humanoid.WalkSpeed = 28
end
end
end
end)
UIS.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
Animation:Stop()
Humanoid.WalkSpeed = 18
elseif input.KeyCode == Enum.KeyCode.ButtonL2 then
Animation:Stop()
Humanoid.WalkSpeed = 18
end
end)
Humanoid.Jumping:Connect(function(jumping)
if jumping and Animation.IsPlaying then
Animation:Stop()
Humanoid.WalkSpeed = 18
end
end)
Humanoid.Running:Connect(function(speed)
if speed == 0 and Animation.IsPlaying then
Animation:Stop()
Humanoid.WalkSpeed = 18
end
end)
Yes
[30 c requirements is epic you can certainly ignore this line]
It fixed it! Thanks! [omg that was an epic 30 c requirement line wasnt it i didnt ignore your line]
Sorry for this revive so late, but another thing I need help with . Basically, since this script is in StarterPlayerScripts, I am not able to access it or change its behavior (disabled or enabled). Is there any way I could change the location and or code of the script to make it so that I can access it?
first of all, you should load the animation onto an animator object so it can replicate to all clients and server
also, you should use ContextActionService instead, it has everything you need, and it’s designed for this kind of stuffs
i edited your script, put it in StarterCharacterScripts
local ContextActionService = game:GetService("ContextActionService")
local Player = game.Players.LocalPlayer
local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")
local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://"
local Animation = Humanoid:FindFirstChildWhichIsA("Animator"):LoadAnimation(Animation)
local Running = false
local Speed = 0
Humanoid.Running:Connect(function(speed)
Speed = speed
end)
function handle(ActionName, InputState, InputObject)
if InputState == Enum.UserInputState.Begin then
if Character.Humanoid.MoveDirection.Magnitude > 0 then
Running = true
while Running do
if not Animation.IsPlaying and Speed > 0 then
Animation:Play()
elseif Speed == 0 then
Animation:Stop()
end
if Humanoid.FloorMaterial == Enum.Material.Air or Humanoid.FloorMaterial == Enum.Material.Water then
Animation:Stop()
end
Humanoid.WalkSpeed = 28
wait()
end
Animation:Stop()
Humanoid.WalkSpeed = 18
end
else
Running = false
end
end
ContextActionService:BindAction("Sprint", handle, true, Enum.KeyCode.ButtonL2, Enum.KeyCode.LeftShift)
First off, thank you so much! Second, how do you think I could refer to call this statement false in other scripts?
sorry but I couldn’t understand, would you mind explaining it a bit?