Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

Sprint not working after death. Help?

Asked by 7 days ago

I am configuring a Stamina Gui. Sprinting, Field of view, and moving stamina bar works. But, when I die, sprinting doesn't work. Every other else work, but the sprinting stop working. I need help.


local camera = game.Workspace.CurrentCamera local TweeningService = game:GetService("TweenService") local UIS = game:GetService('UserInputService') local Bar = script.parent:WaitForChild('STMBackground'):WaitForChild('Bar') local player = game.Players.LocalPlayer local NormalWalkSpeed = 16 local NewWalkSpeed = 50 local power = 10 local sprinting = false repeat wait() until game.Players.LocalPlayer.Character local character = player.Character -- sprinting local FOVChanges = { FieldOfView = 90 } local TweenInformation = TweenInfo.new( 1, --tween length Enum.EasingStyle.Quint, --easing Style Enum.EasingDirection.Out, --easing Direction 0, --repitition time false, --reverse? 0 --delay ) local tween = TweeningService:Create(camera,TweenInformation,FOVChanges) -- walking local FOVChanges2 = { FieldOfView = 70 } local TweenInformation2 = TweenInfo.new( 1, --tween length Enum.EasingStyle.Quint, --easing Style Enum.EasingDirection.Out, --easing Direction 0, --repitition time false, --reverse? 0 --delay ) local tween2 = TweeningService:Create(camera,TweenInformation2,FOVChanges2) UIS.InputBegan:connect(function(key, gameProcessed) if key.KeyCode == Enum.KeyCode.LeftShift and gameProcessed == false then character.Humanoid.WalkSpeed = NewWalkSpeed sprinting = true while power > 0 and sprinting do power = power - .03 Bar.Size = UDim2.new(power / 10, 0, 1, 0) --Bar.BackgroundColor3 = Bar.BackgroundColor3:lerp(Color3.fromRGB(255, 42, 42), 0.001) tween:Play() wait() if power <= 0 then character.Humanoid.WalkSpeed = NormalWalkSpeed end end end end) UIS.InputEnded:connect(function(key, gameProcessed) if key.KeyCode == Enum.KeyCode.LeftShift and gameProcessed == false then character.Humanoid.WalkSpeed = NormalWalkSpeed sprinting = false while power < 10 and not sprinting do power = power + .03 Bar.Size = UDim2.new(power / 10, 0, 1, 0) --Bar.BackgroundColor3 = Bar.BackgroundColor3:lerp(Color3.fromRGB(255, 166, 11), 0.001) tween2:Play() wait() if power <= 0 then character.Humanoid.WalkSpeed = NormalWalkSpeed end end end end) game.Players.LocalPlayer.Character:WaitForChild("Humanoid").Died:connect(function() game.Workspace.Camera.FieldOfView=70 game.Players.LocalPlayer.Character.Humanoid.WalkSpeed=16 end)
0
Quick question, is this script under StarterGui or StarterPlayerScripts / StarterCharacterScripts? Asentis 17 — 7d
0
its on StarterGui Asher0606 0 — 7d
1
Put in under StarterCharacterScripts @Asher0606, a new character is made each time a player respawns but your script doesn't have the reference to it. It only works for the first character since it defines character and plr.Character only once Ankur_007 146 — 7d

Answer this question