Stamina function

I actually do yes, i have set for some players on certain teams to move faster than others, i will see what removing them does

1 Like

You said this earlier, but I would like to point something out: changing a player’s CFrame does NOT reset them. Sorry for the confusion.

That might be what’s causing this. They are interfering with each other for the walkspeed.

Ive removed them all, but it doesnt seem to work. strangely enough putting the script in screengui prints both ‘left shift pressed’ and ‘sprinted’ however putting it in StarterPlayerScripts nothing comes up in console.

Could it be that overwriting the character with skins could be affecting how the character inherits the stamina script? due to the stamina script affecting the character?

1 Like

I wouldn’t recommend putting this specific script in ScreenGUI, since the variables for the character will become invalid if the player resets (unless you set the ScreenGui.ResetOnSpawn property to true).

This shouldn’t be a problem, since the “skins” script is not affecting the character’s walkspeed.

I would suggest putting it in StarterCharacterScripts, as the script will reset when the player dies (which is good for this case)

Also, can you add a print statement above the InputBegan event? This would really help to see if the script is getting to the InputBegan at all.

Yeah i kept a print statement above it, and it prints as soon as the game starts (first thing in the console) but not ever again after that

1 Like

Okay, that’s good. The script is reaching the InputBegan event. Just to make sure, both print statements inside the InputBegan events are printing, correct? Try doing to following for the walkspeed:

character.Humanoid.WalkSpeed = 24

Where do you want me to put that?

1 Like

Here:

userInputService.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift then
        print("Left Shift Pressed")
		if currentStamina >= staminaCost and character.Humanoid.MoveDirection.Magnitude > 0 and IsAllowed then
			character.Humanoid.WalkSpeed = 24
            print("Sprinted")
		end
	end
end)

Where you normally change the walkspeed.

It was normally at 24 as rather than the integer ‘24’ it was just sprintSpeed which was defined as 24. Ive done just the integer anyway, and that doesnt seem to change anything again.

1 Like

Ok, I didn’t think it would.Can you try printing the character walkspeed to see if it is being correctly definded? Like this:

userInputService.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift then
        print("Left Shift Pressed")
		if currentStamina >= staminaCost and character.Humanoid.MoveDirection.Magnitude > 0 and IsAllowed then
            print(character.Humanoid.WalkSpeed)
			character.Humanoid.WalkSpeed = 24
            print("Sprinted")
		end
	end
end)
1 Like

Hi sorry for the late reply,
Yeah ive had those prints in from the start, and BOTH only work when the script is placed in the screenGui as opposed to StarterCharacterScripts (Where when it is in StarterCharacterScripts only the ‘Left Shift Pressed’ print will come up in console)

Something interesting I have just found out is that if I am to manually change the Value of the StringValue ‘SelectedTeam’ ingame (By going to player and changing the value manually) this actually works and then the sprinting function is enabled. So this tells us that the issue here is the automatic changing of the SelectedTeam Value through the code, which im not sure why…

This is how I currently change the value of SelectedTeam automatically in the code:

for i, v in pairs (eligiblePlayers) do
		v.SelectedTeam.Value = "Bodyguards"
	end
	
	for i, v in pairs ({chosenKing}) do
		v.SelectedTeam.Value = "King"
	end
	
	for i, v in pairs (assassinPlayers) do
		v.SelectedTeam.Value = "Assassins"
	end

The terms in the for loop are addressing the selected players for each respective team. Is this way of altering the SelectedTeam Value wrong and hence causing the script to not work?

So it is either the issue of the changing of the SelectedTeam value automatically or something to do with dressing/resetting the players the players when entered into the map

Im also getting this error in console which may be an issue (seems to be when loading into the round map)
Stamina is not a valid member of PlayerGui “Players.Player2.PlayerGui” - Client - LocalScript:26

Corresponding to this line

player.PlayerGui.Stamina.Bar.Size = UDim2.new((current / max)* 0.2, 0,0.05, 0)

1 Like

This could be because of a couple things:

  1. The name might be incorrect. Please make sure that stamina is the name of the ScreenGui.
  2. The GUI might not be loaded in yet, try using WaitForChild()
local Stamina = player.PlayerGui:WaitForChild("Stamina")
Stamina.Bar.Size = UDim2.new((current / max)* 0.2, 0,0.05, 0)

Nothing seems inherently wrong to me, can you try printing the following?

for i, v in pairs (eligiblePlayers) do
        print(v.Name) -- Should print the player's name
        print(v.SelectedTeam.Value) -- Should print the value before you change it
		v.SelectedTeam.Value = "Bodyguards"
        print(v.SelectedTeam.Value) -- Should print the value "Bodyguards"
	end
	
	for i, v in pairs ({chosenKing}) do
		v.SelectedTeam.Value = "King"
	end
	
	for i, v in pairs (assassinPlayers) do
		v.SelectedTeam.Value = "Assassins"
	end
1 Like

Thanks for putting the time in to help btw, I appreciate it :slight_smile:

Added the waitforchild in, and adding those print statements it prints:

Player1
Lobby
Bodyguards

It doesnt make sense, just before the player teleported into the map I manually changed the SelectedTeam value to a random word and the sprinting worked in the lobby, but WHEN teleporting in the map (SelectedTeam value changing from this random word to one of the 3 King,Assassin,Bodyguard) the sprint function no longer worked so it must have something to do with this teleporting into the map, ALSO as when i try and change it to a random word in the map, it doesnt even work then only when thats done in the lobby…

It must have something to do with the character taking on a preset model surely

1 Like

Hey would you mind sending me a friend request and a team create invite? I think I will be able to help you better if I can see the entire code myself. I think this problem has gotten a little to confusing to be relayed with back-and-forth messages :upside_down_face: