Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Coin that adds leader stats on contact, I need a script that gives a player leader stats, how?

I just need a script to add to my coins in my game

and saves, I don't know how to do this since I'm not familiar with things that save your progress

2 answers

✓ Accepted answer

Hey there.

-- In 'ServerScriptService', add this into a script named 'PlayerSetup'
local function onPlayerJoin(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
 
	-- Display an 'IntValue' on leaderboard
	local gold = Instance.new("IntValue")
	gold.Name = "Gold"
	gold.Value = 0
	gold.Parent = leaderstats
end
 
-- Run 'onPlayerJoin()' when the 'PlayerAdded' event fires
game.Players.PlayerAdded:Connect(onPlayerJoin)

This script can be found in this article: https://developer.roblox.com/en-us/articles/Leaderboards

If you'd like to have the player save his gold, then you should give this article a look: https://developer.roblox.com/en-us/articles/Saving-Player-Data

Happy scripting!

2 comments

0

I dont understa d so im going to watch a video

0

Can do! Good luck finding your solution.

leaderstats are those things you see at the top right of your screen (usually) when you join the game. Leaderstats is using an event called Players.PlayerAdded.

game.Players.PlayerAdded:Connect(function(plr) --parameter is the player joining
end)

Then we will add a Folder which is the leaderstats itself.

game.Players.PlayerAdded:Connect(function(plr)
	local leaderstats = Instance.new("Folder") --Creates a folder, we haven't got a parent.
	leaderstats.Name = "leaderstats" --Adds the name.
	leaderstats.Parent = plr --Moves the leaderstats script into the LocalPlayer folder.
end)

Now we have got the leaderstats itself, however, we haven't got any data. Let's add 2 values, IntValue and StringValue.

game.Players.PlayerAdded:Connect(function(plr)
	local leaderstats = Instance.new("Folder") 
	leaderstats.Name = "leaderstats" 
	leaderstats.Parent = plr

	local points = Instance.new("IntValue") --Int is short for Integer, which is whole numbers.
	points.Name = "Points" 
	points.Parent = leaderstats --Moves the IntValue to the leaderstats folder.

	local rank = Instance.new("StringValue")
	rank.Name = "Rank"
	rank.Parent = leaderstats --Moves the StringValue to the leaderstats folder. 
	--1st will be the points, and the 2nd will be the rank. 
end)

Now for saving, I suggest you go to Devking's video about DataStoreService. However, for your purpose it's this:

game.Players.PlayerAdded:Connect(function(plr)
	local leaderstats = Instance.new("Folder") 
	leaderstats.Name = "leaderstats" 
	leaderstats.Parent = plr

	local coins = Instance.new("IntValue") --Int is short for Integer, which is whole numbers.
	coins.Name = "Coins" 
	coins.Parent = leaderstats --Moves the IntValue to the leaderstats folder.
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.