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

What do I do to change the value of a child in leaderboards?

So, I've made my own coin, that when you touch it, it plays a sound and disappears. Now, I'm trying to also make it, that when I touch it, I get one point in the leader board. Here's my coin script so far. It's in a part.

local part = script.Parent
local db = false




function coin(hit)
	local human = hit.Parent:FindFirstChild("Humanoid")
	
	if not db then
		if human then
			db = true
			
			game.Workspace.Sound:Play()
			script.Parent:Destroy()
			wait(1.2)
			game.Workspace.Sound:Stop()
			
		human.leaderstats.coin.Value = human.leaderstats.coin.Value + 1
		
			
			db = false
			
		end
	end
end


part.Touched:connect(coin)

while wait() do
	part.CFrame = part.CFrame * CFrame.Angles(0,0,0.1)
end

So, my coin spins the way it should, it plays the sound and destroys itself the way it should, it just doesn't give my stats an extra point. Any ideas? I hope this isn't a complicated answer. If it is, please explain it to me.

2 comments

0

So the leaderstats are in the humanoid?

0

Leaderstats can't be in the humanoid, that question shouldn't even be a question :P

2 answers

✓ Accepted answer

Hey, there was a simple mistake on your script. Firstly, the script is a mess and needs to be cleaned up a little. For now, since i'm in a rush, i'll provide you with the solution.

THE ERROR

You tried to get the player's leaderstats by accessing the player's humanoid and not the player itself. The leaderstats are located in the player, not the player's character or humanoid, but the player itself.

IMPROVEMENTS

I'd suggest moving the Sound inside the coin and replacing "game.Workspace.Sound" to "script.Parent.Sound" for better results.

THE SOLUTION

local part = script.Parent
local db = false

function coin(hit)
local human = hit.Parent:FindFirstChild("Humanoid")
if not db then
if human then
db = true
local character = game.Players:GetPlayerFromCharacter(hit.Parent)
game.Workspace.Sound:Play()
script.Parent:Destroy()
wait(1.2)
game.Workspace.Sound:Stop()

character.leaderstats.coin.Value = character.leaderstats.coin.Value + 1
db = false
end
end
end

part.Touched:connect(coin)

while wait() do
part.CFrame = part.CFrame * CFrame.Angles(0,0,0.1)
end

Hope this helped! Be sure to accept the answer if everything works!

Add the script.Parent:Destroy() after you hand out the points

2 comments

0

Now nothing works. :P

0

Is it like directly after the leaderstats = leaderstats + 1?

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