while browsing through youtube and the devforum, I came across this post
I used the solution on that post to make a local coin, and it worked…Partially. The script used only makes the coin disappear for one player and still appear for the other players. When collecting the coin, it’s collection is server wide, which makes it so that other players can’t collect the coin. I’ve been stuck on this for so long because I don’t know where to start and every youtube tutorial only knows how to make the coin shown in that post!
I want to know where I can start on how to make it so that it’s collected for one player but it hasn’t been collected for the other
script that goes in the coin
--in the part
local debounce = false
local db=true
local remote = game.ReplicatedStorage.CoinEvent --Make this the remote event
script.Parent.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr and db then
if 1 + 1 == 2 then --change
if debounce == false then
debounce = true
db = false
plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value + 25--change
remote:FireClient(plr, script.Parent)
db = true --Make sure other players can get it
wait(9000000)
debounce = true
end
end
end
end)
local remote = game.ReplicatedStorage.CoinEvent --Make this the remote event
Hi, you can easily solve the problem by just making a table which includes the players that collected the coin.
Like this.
CoinCollected = {}
script.Parent.Touched:Connect(function(hit)
if table.find(CoinCollected, game.Players:GetPlayerFromCharacter(hit.Parent)) == nil then
--add stuff
table.insert(CoinCollected, game.Players:GetPlayerFromCharacter(hit.Parent))
end
end
(On the server script)
And you can make the coin invisible to a client after a player collects it by firing a remote event.
local remote = game.ReplicatedStorage:WaitForChild("CoinEvent")
game.Players.LocalPlayer.CharacterAdded:Connect(function(character)
character:WaitForChild("Humanoid").Touched:Connect(function(part)
if part.Name == "Coin" then -- change "Coin" to whatever name is your local coin
part:Destroy()
remote:FireServer(part)
end
end)
end)
Script in coin:
local remote = game.ReplicatedStorage:WaitForChild("CoinEvent")
remote.OnServerEvent:Connect(function(player, part)
if part == script.Parent then
player.leaderstats.Coins.Value += 25
end
end)