|
| 12 Mar 2016 11:15 AM |
--\\ Services local Players = game:GetService("Players"); local UserInputService = game:GetService("UserInputService");
--\\ LocalPlayer Variables local Player = Players.LocalPlayer local Character = Player.Character or Player.CharacterAdded:wait() local Humanoid = Character.Humanoid local StaminaValue = Player:WaitForChild("Stamina")
--\\ Debounce Variables local Running = false
--\\ Getting Input UserInputService.InputBegan:connect(function(Input,GPE) if Input.UserInputType == Enum.UserInputType.Keyboard and not GPE and not Running then if Input.KeyCode == Enum.KeyCode.LeftShift then Running = true end end end)
UserInputService.InputEnded:connect(function(Input,GPE) if Input.UserInputType == Enum.UserInputType.Keyboard and not GPE and Running then if Input.KeyCode == Enum.KeyCode.LeftShift then Running = false end end end)
game:GetService("RunService").RenderStepped:connect(function() if Running and StaminaValue.Value > 0 then Humanoid.WalkSpeed = 23 StaminaValue.Value = StaminaValue.Value > 0 and StaminaValue.Value - 1 or StaminaValue.Value if StaminaValue.Value < 1 then Humanoid.WalkSpeed = 16 Running = false end else Humanoid.WalkSpeed = 16 StaminaValue.Value = StaminaValue.Value < 100 and StaminaValue.Value + 1 or StaminaValue.Value end end)
There are no errors. It works once but then breaks when the player dies. Help please |
|
|
| Report Abuse |
|
|
| |
|
KLGA
|
  |
| Joined: 19 Apr 2014 |
| Total Posts: 2571 |
|
|
| 12 Mar 2016 11:49 AM |
Might be because of this:
game:GetService("RunService").RenderStepped:connect(function() if Running and StaminaValue.Value > 0 then Humanoid.WalkSpeed = 23 StaminaValue.Value = StaminaValue.Value > 0 and StaminaValue.Value - 1 or StaminaValue.Value if StaminaValue.Value < 1 then Humanoid.WalkSpeed = 16 Running = false end else Humanoid.WalkSpeed = 16 StaminaValue.Value = StaminaValue.Value < 100 and StaminaValue.Value + 1 or StaminaValue.Value end end)
More specifically, this:
Humanoid.WalkSpeed = 23
That runs with every single frame of the game, when the player respawns there is a short period of time where their Character is nil. Try changing how you define Humanoid to something like:
local Humanoid = Character:WaitForChild("Humanoid") |
|
|
| Report Abuse |
|
|
|
| 12 Mar 2016 11:51 AM |
| I just did that and it still didn't work :( |
|
|
| Report Abuse |
|
|
KLGA
|
  |
| Joined: 19 Apr 2014 |
| Total Posts: 2571 |
|
|
| 12 Mar 2016 11:53 AM |
Make sure 'running' is true and 'StaminaValue' is > 0.
Print them out at the beginning and see what their values are:
game:GetService("RunService").RenderStepped:connect(function() print(Running,StaminaValue.Value) if Running and StaminaValue.Value > 0 then Humanoid.WalkSpeed = 23 StaminaValue.Value = StaminaValue.Value > 0 and StaminaValue.Value - 1 or StaminaValue.Value if StaminaValue.Value < 1 then Humanoid.WalkSpeed = 16 Running = false end else Humanoid.WalkSpeed = 16 StaminaValue.Value = StaminaValue.Value < 100 and StaminaValue.Value + 1 or StaminaValue.Value end end) |
|
|
| Report Abuse |
|
|
|
| 12 Mar 2016 11:55 AM |
When I reset and I pressed shift, I started jumping
But what printed was "false 100" |
|
|
| Report Abuse |
|
|
KLGA
|
  |
| Joined: 19 Apr 2014 |
| Total Posts: 2571 |
|
|
| 12 Mar 2016 11:58 AM |
| I tested your script and it seemed to work, Running was changing to false and true depending on whether or not shift was pressed. |
|
|
| Report Abuse |
|
|
|
| 12 Mar 2016 12:01 PM |
It doesn't work for me ;-;
Want to see? |
|
|
| Report Abuse |
|
|
KLGA
|
  |
| Joined: 19 Apr 2014 |
| Total Posts: 2571 |
|
|
| 12 Mar 2016 12:02 PM |
| When you print the Running value, it's not changing at all when you press shift? |
|
|
| Report Abuse |
|
|
|
| 12 Mar 2016 12:04 PM |
| no. Follow me into my place called "Quake Mayhem" |
|
|
| Report Abuse |
|
|
|
| 12 Mar 2016 12:07 PM |
don't change the speed locally
Recommended username: MarkedRay_revenge
|
|
|
| Report Abuse |
|
|
KLGA
|
  |
| Joined: 19 Apr 2014 |
| Total Posts: 2571 |
|
|
| 12 Mar 2016 12:09 PM |
| I don't really think there would be a difference^ |
|
|
| Report Abuse |
|
|
|
| 12 Mar 2016 12:10 PM |
I tested it in studio i assume roblox did it for security reasons
make a localscript set the localplayer's speed to 40 or w/e, reset, then it won't work
Recommended username: JumbledRay_revenge
|
|
|
| Report Abuse |
|
|