Gold Leaderboard issue

  1. What do you want to achieve?
    Whenever the person click on the part, a gold pops up and the person is able to touch it and increase his gold reserve in the leaderboard.

  2. What is the issue?
    The code doesn’t seem to work.

  3. What solutions have you tried so far?

Didn’t find anything that could help me on the Developer Hub, so please respond to me as soon as possible.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local part = workspace.test
local Click = part.ClickDetector
local gold = ReplicatedStorage.gold

local function clicked()
	local goldd = gold:Clone()
	goldd.Position = part.Position
	goldd.Parent = workspace
end

local function goldtouched(hit)
	local Humanoid = hit.Parent:FindFirstChild("Humanoid")
	
	if Humanoid then
		local Gold = hit.Parent.leaderstats.Gold
		
		Gold.Value = Gold.Value + 1
	end
end

Click.MouseClick:Connect(clicked)
goldd.Touched:Connect(goldtouched)
2 Likes

Can you exactly explain what doesnt work?

1 Like

Clicking and generating a gold works well. However, touching the gold to increase your amount of gold in leaderboard doesn’t work.

2 Likes

There is a typo in the last line, it should be gold with one “d”, right?

1 Like

Well the reason is that hit.Parent means character, leaderstats is placed in player. Chaneg this:

local Gold = hit.Parent.leaderstats.Gold

to

local Player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
local Gold = Player:FindFirstChild("leaderstats").Gold

Actually, I did it on purpose.

Nope, Doesn’t seem to work either.

1 Like

Actually, you’re right. It’s supposed to be with one “d”. But even then, It’s still doesn’t work.

1 Like

Any errors?

3424242343242342342342334

Nope, and pretty cool numbers you got there.

1 Like

I added print() on each line in the function and it seems like the function isn’t even getting passed through.

1 Like

Well, I did the same and didnt work. I changed script so it looks different, but does the same

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local part = workspace.test
local Click = part.ClickDetector
local gold = ReplicatedStorage.gold


Click.MouseClick:Connect(function()
	local goldd = gold:Clone()
	goldd.Position = part.Position
	goldd.Parent = workspace
	
	goldd.Touched:Connect(function(hit)
		local Humanoid = hit.Parent:FindFirstChild("Humanoid")

		if Humanoid then
			print("found humanoid")
			local Player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
			if Player then
				print("found player")
				local Gold = Player:FindFirstChild("leaderstats").Gold
				if Gold then
					print("found gold")
					Gold.Value = Gold.Value + 1
				end
			end
		end	
	end)
end)
1 Like

Thank you so much! I never thought of putting the Touched function in the Click function lol

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.