I have been experimenting for a while and the closest i can get to is
1 | function onTouched(part) |
2 | local leaderstats = Instance.new( "Folder" ) |
3 | leaderstats.Name = "leaderstats" |
4 | -- Display an 'IntValue' on leaderboard |
5 | local Coins = Instance.new( "IntValue" ) |
6 | Coins.Name = "Coins" |
7 | Coins.Value = Coins.Value + 200 |
8 | Coins.Parent = leaderstats |
9 | end |
Any ideas on what was done wrong?
You almost got it right! But there is 1-2 problems stopping you from completing your ask, let me help you out.
01 | local function onTouched(part) |
02 | if part.Parent:FindFirstChildOf( 'Humanoid' ) then -- first check if it's a potential player |
03 | local player = game.Players:GetPlayerFromCharacter(part.Parent) -- see if its a player |
04 | if player then -- final check |
05 |
06 | if Player:FindFirstChild( 'leaderstats' ) = = nil then -- check if player already has leaderstats or not |
07 | local leaderstats = Instance.new( 'Folder' , player) -- you forgot to parent it |
08 | leaderstats.Name = 'leaderstats' |
09 | local Coins = Instance.new( 'IntValue' , leaderstats) |
10 | Coins.Name = "Coins" |
11 | Coins.Value = 0 -- default value at start |
12 | end |
13 |
14 | if player:FindFirstChild( 'leaderstats' ) ~ = nil then -- check if player now has leaderstats player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 200 -- give them 200 coins |
15 |
01 | local function onTouched(part) |
02 | local plr = game.Players:GetPlayerFromCharacter(part.Parent) |
03 | if plr then -- If its a player |
04 | if not plr:FindFirstChild( "leaderstat" ) then -- Check if player already has leaderstats or not |
05 | local leaderstats = Instance.new( "Folder" , plr) -- Create leaderstats then parent it to the player |
06 | leaderstats.Name = "leaderstats" |
07 | local Coins = Instance.new( "IntValue" , leaderstats) |
08 | Coins.Name = "Coins" |
09 | Coins.Value = 0 -- Default value at start |
10 | end |
11 | if plr:FindFirstChild( "leaderstats" ) ~ = nil then -- Check if player now has leaderstats |
12 | plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value + 200 -- Give them 200 coins |
13 | end |
14 | end |
15 | end |