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!
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)
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?