Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you make a Object add money onto a Leaderboard? [closed]

Asked by 7 years ago

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!

0
Btw my actual account is DarknessFriggus, I forgot what my old account for this was. DARKSTAR1236353456 -5 — 7y
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 M39a9am3R 3210 — 7y
0
@M39 Yeah it was from ages and ages ago. DARKSTAR1236353456 -5 — 7y
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 ) DesiredRep 75 — 7y

Closed as Not Constructive by ChipioIndustries, JamesLWalker, jjwood1600, and RubenKan

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?

1 answer

Log in to vote
0
Answered by
Thetacah 712 Moderation Voter
7 years ago
Edited 7 years ago

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 .Touchedevent. 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)

0
**identation** RubenKan 3615 — 7y
Ad