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.
01 | local CAS = game:GetService( "ContextActionService" ) |
02 | local RE = game:GetService( "ReplicatedStorage" ):WaitForChild( "RE" ) |
03 | local fill = script.Parent:WaitForChild( "top" ):WaitForChild( "fill" ) |
04 |
05 | local stam = 50 |
06 | local speed = 16 |
07 | local sprinting = false |
08 |
09 | local function sprint (str,state,object) |
10 | if stam < 1 then return end |
11 | speed = state = = Enum.UserInputState.Begin and 24 or 16 |
12 | sprinting = state = = Enum.UserInputState.Begin |
13 | while sprinting and stam > 0 and wait(. 1 ) do |
14 | stam = stam - 1 |
15 | fill:TweenSize(UDim 2. new(stam/ 50 , 0 , 1 , 0 ), "Out" , "Quint" , . 1 , true ) |
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:
01 | --variables |
02 | local textlabel = script.Parent |
03 | local player = game.Players.localPlayer |
04 | local stamina = 100 |
05 | local uis = game:GetService( "UserInputService" ) |
06 | local isSprinting = false |
07 |
08 |
09 |
10 | uis.InputBegan:Connect( function (key) |
11 | if key.KeyCode = = Enum.KeyCode.LeftShift and stamina > 0 then |
12 | isSprinting = true |
13 | player.Character.Humanoid.WalkSpeed = 25 |
14 | while key.KeyCode = = Enum.KeyCode.LeftShift and stamina > 0 and isSprinting = = true do |
15 | stamina = stamina - 1 |