Made this awhile back and want to get started at making my own game. Idky my sprinting script aint working, but the gui is working which is great. If you can help, it would be greatly appreciated.
local CAS = game:GetService("ContextActionService") local RE = game:GetService("ReplicatedStorage"):WaitForChild("RE") local fill = script.Parent:WaitForChild("top"):WaitForChild("fill") local stam = 50 local speed = 16 local sprinting = false local function sprint (str,state,object) if stam <1 then return end speed = state == Enum.UserInputState.Begin and 24 or 16 sprinting = state == Enum.UserInputState.Begin while sprinting and stam > 0 and wait(.1) do stam = stam - 1 fill:TweenSize(UDim2.new(stam/50, 0, 1, 0),"Out","Quint", .1, true) RE:FireServer('sprint', (speed)) end sprinting = false speed = 16 RE:FireServer('sprint', (speed)) wait(1) while not sprinting and stam < 50 and wait (.5) do fill:TweenSize(UDim2.new(stam/50, 0, 1, 0), "Out", "Quint", .1, true) stam = stam +0.5 end end CAS:BindAction("sprint", sprint, true, Enum.KeyCode.LeftShift) --sprinting does not work, but the gui is currently working when you hold down, and it also regens back.
I have no clue what the remote event is connected to, so I'll answer based on all the code posted here: You forgot to set the WalkSpeed property of the localplayer's humanoid.
Oh and, you are also carelessly passing through the speed value, which could very easily be exploited. Instead, try sending all the keys pressed over to the server, and have the server handle stuff such as sprinting.
hey man, i dont know to much of really advanced scripting but i recently made a sprint script with a gui as well and ill link that to you here to look through:
https://www.roblox.com/library/3455933485/SprintGUI
alternatively here is the script for it:
--variables local textlabel = script.Parent local player = game.Players.localPlayer local stamina = 100 local uis = game:GetService("UserInputService") local isSprinting = false uis.InputBegan:Connect(function(key) if key.KeyCode == Enum.KeyCode.LeftShift and stamina >0 then isSprinting = true player.Character.Humanoid.WalkSpeed = 25 while key.KeyCode == Enum.KeyCode.LeftShift and stamina >0 and isSprinting == true do stamina = stamina -1 print(stamina) wait(0.1) if stamina <= 0 then isSprinting = false player.Character.Humanoid.WalkSpeed = 16 end end wait(0.1) end end) uis.InputEnded:Connect(function(key) if key.KeyCode == Enum.KeyCode.LeftShift then isSprinting = false player.Character.Humanoid.WalkSpeed = 16 wait(2) while key.KeyCode == Enum.KeyCode.LeftShift and stamina <100 and isSprinting == false do stamina = stamina +1 wait(0.1) print(stamina) end end end) while wait (0.1) do textlabel.Text = ("Sprint: "..stamina) end