Removing coin for only one player

Hi,

I have a remote event and the script below in a local script to remove a coin for a player when they collect but it’s removing for all players and I am not certain why?

game.ReplicatedStorage.CollectCoin.OnClientEvent:Connect(function(coin)
coin:Destroy()
end)

1 Like

did you use Remote:FireAllClients or Remote:FireClient?

Did you use FireAllClients or encompassed FireClient within a loop?

1 Like

Hi,

the code is

game.ReplicatedStorage.CollectCoin:FireClient(Player,script.Parent)

What does all of the code in the script look like

– ServerScript under Part in Workspace
local Value = 1
local Enabled = true
local repStorage = game:GetService(“ReplicatedStorage”)

script.Parent.Touched:Connect(function(hit)
if Enabled then
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
if Player then
local lstats = Player:WaitForChild(“leaderstats”)
lstats.Coins.Value = lstats.Coins.Value + Value
Enabled = false
script.Parent.Transparency = 1

		local playerSound = repStorage:WaitForChild("PlaySound")
		playerSound:FireClient(Player, 1)
		
		local collectCoin = repStorage:WaitForChild("CollectCoin")
		collectCoin:FireClient(Player, script.Parent)
		
	end
end

end)

– Local Script inside StarterPlayerScripts
game.ReplicatedStorage.CollectCoin.OnClientEvent:Connect(function(coin)
coin:Destroy()
end)

the coin is still there for everyone else, the server just makes it invisible
Have the localscript make it invisible

Hi,

When I run a local test server with two players both players see the coin disappear

Did you update the script? Try putting a print function inside the localscript’s .OnClientEvent scope to see if it does fire for both players. If so, this might be a roblox bug

Remove the script.Parent.Transparency = 1 line inside the server script, that way it’ll disappear on the client who collected the coin but on the server it will stay visible

Thanks is was the server script I did not notice the transparency line

Thanks for the help

Np, make sure to mark it as a solution so that people know about this being solved