Making a stats GUI that if you have enough points, you can increase your speed stat by +1, increasing the player’s walkspeed by +1, eachtime it increases it’s stored inside an IntValue.
I had a problem where the player’s IntValue reset whenever the player dies, but i realized the IntValue doesn’t reset inside PlayerGui, so i changed my join script:
If this is the issue you are looking to fix, try experimenting with CharacterAdded instead of PlayerAdded. The difference is that CharacterAdded fires everytime the player character respawns, while PlayerAdded only fires everytime a Player is added (when a player joins).
I think this script might work better since CharacterAdded is at the top, you don’t really need PlayerAdded for your use case, to my knowledge. (For future use: this script I posted will not work, please do not use it as is.)
From what I know the CharacterAdded event requires the Player object, not the Player service.
PlayerAdded is used before it because it returns the Player object and then you use it on the CharacterAdded event, which is necessary.
There’s nothing wrong with using PlayerAdded event also since everytime a player joins the game it’ll be activated and CharacterAdded will also be connected to the player.
CharacterAdded will fire everytime the player spawns/respawns It does not need PlayerAdded to fire once again.
It’s a Script in Workspace, when the player joins, it sets the player’s speed according to the IntValue which starts at 1, when the IntValue changes and the player resets, logically it should set it to the IntValue, but it somehow gets the value of 1, what’s happening? (I check what value it is in the PlayerGui and it is the correct value, which let’s say is… 7 at this moment.)
The script that increases the value is a LocalScript, because you increase the value by clicking on a GUI if you have enough points to increase it (IntValue inside GUI too.), is there a way without a local script?
Perhaps confusingly you are using argument called players instead of player or plr, which is more common. PlayerAdded provides single player. This is not an error, but you may want to change it.
Now on to the topic:
There is no way this could work the way you describe, unless your gui is set not to reset on spawn (ResetOnSpawn) on your main screen is deselected. (default is “on”) If it is on, player GUI will be copied from StarterGui and old one lost. So your value will be reset to 1 (or whatever is set in StarterGui)
If you can fix this, bear in mind that this is a very exploit prone method to keep track of player in-game data.
The IntValue resets back to 1 in the StarterGui, no matter if ResetOnSpawn is on, however since it doesn’t reset in the PlayerGui, i thought i would utilize it.
Would you consider moving all of the IntValues onto ServerStorage, only with the client sending RemoteEvents to update the value? That way, the GUI is simply a sort of “fire” button for the RemoteEvent.