Has anyone get a script to add a IntValue into joined players? Im trying to make a custom money script but i need to insert a int value.
Hi,
First of all, I'd like to say that this is in no means a request
site.
To accomplish what you want to do, you need to use the PlayerAdded
event. This event fires every time someone joins
the game. PlayerAdded has a parameter which is the player that joined the game.
For example: This will print the name of the player that has joined the game.
game.Players.PlayerAdded:connect(function(plr) --PlayerAdded Anonymous function. Is fired from Players print(plr.Name) --Prints the player that joined's name using the "Plr" parameter and the .Name attribute. end)
You can read more about the PlayerAdded event here.
On the contrary, you can use the PlayerRemoving
event, which also has the player as parameter;and this runs when a player left the game.
Same thing, this will print the player that has left the game.
game.Players.PlayerRemoving:connect(function(plr) print(plr.Name) end)
You can read more about the PlayerRemoving event here.
Now, since you want a 'Money' script, I can only assume you want it to show up on the leaderboard.
Since we only want the values to be created once
, we will use the PlayerAdded
event.
plradded(plr) end game.Players.PlayerAdded:connect(plradded)
After this step, you should start by adding an object to the player named leaderstats
. This object should be a Model
or a Folder
. Don't forget to parent it to the player
plradded(plr) local leaderstats = Instance.new("Model", leaderstats) --Creating a model leaderstats.Name = "leaderstats" --If it's not named leaderstats, it won't work. end game.Players.PlayerAdded:connect(plradded)
Next, add all your values you want to be shown on the leaderboard.(Points, Money, etc). They should be parented to leaderstats.
plradded(plr) local leaderstats = Instance.new("Model", leaderstats) --Creating a model leaderstats.Name = "leaderstats" --If it's not named leaderstats, it won't work. local Money = Instance.new("IntValue", leaderstats) -- Creating an int number as it will be a number and parenting it to leaderstats with a comma Money.Name = "Moneyz" --This is the name it will appear as on the leaderboard Money.Value = 100--Chaning the value of the money to 100 when they join the game end game.Players.PlayerAdded:connect(plradded)
That should make it final!
You can read more about leaderboards here.
If you didn't want it to be a leaderboard, you do the same thing just with no leaderstats
and parent everything to the player
game.Players.PlayerAdded:connect(function(plr) local money = Instance.new("IntValue", plr) money.Name = "Money" money.Value = 100 end)
Closed as Not Constructive by EzraNehemiah_TF2 and User#6546
This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.
Why was this question closed?