✓ Accepted answer
You almost got it! :O
It's pretty complicated, but how you'd accomplish this is using the Touched event of a part to listen for when a player touches the part, and then to execute code that adds to your money stat. Then, to get the player, we could use the GetPlayerFromCharacter function to check whether what touched the part was a player or not. (Neat thing about it is that it'll return the player too ^-^)
Now, ONTO TEH CODE!
local thePart = script.Parent
local players = game:GetService('Players')
function addToStat(hit)
if hit.Parent then
local thePlayer = players:GetPlayerFromCharacter(hit.Parent)
if thePlayer and thePlayer:FindFirstChild('leaderstats') and thePlayer.leaderstats:FindFirstChild('Money') then
thePlayer.leaderstats.Money.Value = thePlayer.leaderstats.Money.Value + 1
con:Disconnect()
thePart:Destroy()
end
end
end
con = thePart.Touched:Connect(addToStat)
And that's pretty much all there's to it. <->
STUFF MENTIONED BUT NEVER REALLY TALKED ABOUT!
FindFirstChild - Checks if a certain child exists. The function goes as so: Parent:FindFirstChild('CHILD_NAME')
Events - In a nutshell, to connect the object to a listener to listen for something to happen. [Like the Touched event in the above code]
Destroy - Pretty self-explanatory. Just destroys an object.
Touched - Listens for when something touches the part the listener is set up to.
Players Service - The ultimate service that handles all the players.
GetPlayerFromCharacter - This function is pretty neat; in a nutshell, if what you gave it was a player's character, it'll return the player, and if not it'll return a boolean called nil. The function is as goes: Players:GetPlayerFromCharacter(Some_Model)
I hope this helped. :)
2 comments
Well, props for trying...
Oh lord.....