Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Shift to Sprint script not working, need assistance; If possible?

Asked by 5 years ago

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.

01local CAS = game:GetService("ContextActionService")
02local RE = game:GetService("ReplicatedStorage"):WaitForChild("RE")
03local fill = script.Parent:WaitForChild("top"):WaitForChild("fill")
04 
05local stam = 50
06local speed = 16
07local sprinting = false
08 
09local 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(UDim2.new(stam/50, 0, 1, 0),"Out","Quint", .1, true
View all 30 lines...
0
I feel like its the lines 11 and 12 that is making it not work, but I don't know. Any errors? UltraUnitMode 419 — 5y
0
no errors, code went through well, just that when I press shift, im not running at all. garbnothrow2 3 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

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.

0
lol youre talking way too smart, can you help me out further? I am confused. How do I send all key press to server? garbnothrow2 3 — 5y
0
Easy, set up a pressed keys table, and whenever a key gets pressed, add the keycode of that key into the table with a value of true, and if the key gets released, set the value to nil. Then, each time a key gets pressed or released, fire a remote event with the keys table, and set up a server script that copies the list into a pressedkeys table, with the key being the player's userid DarkageMast3r 140 — 5y
0
If you message me on roblox, I'll link you a demo that has this in place. DarkageMast3r 140 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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
02local textlabel = script.Parent
03local player = game.Players.localPlayer
04local stamina = 100
05local uis = game:GetService("UserInputService")
06local isSprinting = false
07 
08 
09 
10uis.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
View all 46 lines...

Answer this question