Why is money showing to everyone on gui

so ive got a script that when a coin collects it adds one to leaderstats stats and shows money on gui
but when theres 2 players and somebody gets it it shows to everyone heres the script (local script btw)

local player = game.Players.LocalPlayer
local ringslabel = script.Parent
local Rings_Folder = game.Workspace.RingsFolder
local cangetcoin = true
local CDCoin = 0.1
local Amount_Rings_Value = 1
local Amount_Particle = 10
local RingParticleFolder = game.Workspace.RingParticlesFolder
local RingSound = script.RingEffect
local DB = false
local Amount_Circle_Particle = 1
local ParticlePart = RingParticleFolder.RingParticle

local leadercubes = player.leaderstats.Cubes
leadercubes.Changed:Connect(function(val)
	if player then
		ringslabel.Text = "Cubes: ".. val
	end
end)
ringslabel.Text = "Cubes: ".. leadercubes.Value

for i, v in pairs(Rings_Folder:GetChildren()) do
	v.Touched:Connect(function(hit)
		local hum = hit.Parent:FindFirstChild("Humanoid")
		local particle_cloned = false
		if hum and DB == false then
			DB = true
			v:Destroy()
			if particle_cloned == false then
				particle_cloned = true
				ParticlePart.Position = v.Position
				ParticlePart.Particle:Emit(Amount_Particle)
				ParticlePart.Particlecircle:Emit(Amount_Circle_Particle)
				if cangetcoin == true then
					cangetcoin = false
					leadercubes.Value += Amount_Rings_Value
					RingSound:Play()
				end
				wait(CDCoin)
				DB = false
				cangetcoin = true
				v:Destroy()
			end
		end
	end)
end

did u used a normal script or local script

its says but its in local script

You are just checking if anyone touches the thing that gives you the stat. If anything with a humanoid touches it, the script adds it’s local player the stat, and it doesn’t matter which player touches it. You need to check if the player that touches it is the player you are adding the stat for.
Instead of this: if hum and DB == false then, you could do something like:
if hum and hum.Parent == player.Character and DB == false then.

Also, you are doing this in a local script, you should change a player’s leaderstat in server scripts only, if it’s done locally, the server won’t know how much the player has (meaning you wouldn’t be able to save for example).
You should check for the .Touched in a serverscript, in the .Touched function check what player touched it, and add the stat for that player only (still on the server).
The gui-changing would be done locally though.

1 Like

thx i understand now! and thx for helping!

1 Like