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

How do you make a Object add money onto a Leaderboard?

Basically, what I am trying to do is the following:

Make a Chest which on touch removes. Then It adds on Money (Lets say 10) Onto the Leaderstats.

I need the Leaderstats part. If anyone could help this would help me complete my first step for my game!

4 comments

0

Btw my actual account is DarknessFriggus, I forgot what my old account for this was.

0

It appears your previous account name was bozley56. Try resetting your password for that account. If you can not get a password reset link due to an invalid email or other reason, contact support at https://scriptinghelpers.org/contact

0

@M39 Yeah it was from ages and ages ago.

0

script.Parent.Touched:connect(function(hit) if hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") then game.leaderstats.money.Value = game.leaderstats.money.Value + 10 end end )

1 answer

This site is not for requests, but since I'm feeling nice I can give you a quick sample. Of course, this is just a basic script that you might want to add more checks or things to improve efficiency.

You would accomplish this by using the .Touched event. You can read more about that here:

I do know that this script can be flawed, but it should work.

local part=script.Parent --The script is in the part that would give you money


part.Touched:connect(function(hit) --Creating our anonymous function. -Fires when anything hits the part

end)

Now that we are inside the .Touched function:

if(game.Players:GetPlayerFromCharacter(hit.Parent) and hit.Parent:FindFirstChild("Humanoid") and hit.Parent:FindFirstChild("Humanoid").Health>0) then --Making sure what hit the part was indeed a player...an alive player.

local player=game.Players:GetPlayerFromCharacter(hit.Parent)
local leaderstats=player:WaitForChild("leaderstats", 5) --Waiting for leaderstats in the player

if(leaderstats) then
local money=leaderstats:FindFirstChild("Money")
if(money) then
money.Value=money.Value+50 --Increasing the player's money value by 50
end

end 

end
part:Destroy() --Destroy the part at the end

Full script:

local part=script.Parent --The script is in the part that would give you money


part.Touched:connect(function(hit) --Creating our anonymous function. -Fires when anything hits the part
if(game.Players:GetPlayerFromCharacter(hit.Parent) and hit.Parent:FindFirstChild("Humanoid") and hit.Parent:FindFirstChild("Humanoid").Health>0) then --Making sure what hit the part was indeed a player...an alive player.

local player=game.Players:GetPlayerFromCharacter(hit.Parent)
local leaderstats=player:WaitForChild("leaderstats", 5) --Waiting for leaderstats in the player

if(leaderstats) then
local money=leaderstats:FindFirstChild("Money")
if(money) then
money.Value=money.Value+50 --Increasing the player's money value by 50
end

end 

end
part:Destroy() --Destroy the part at the end

end)

1 comment

0

identation

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