So I wrote this script that allows a player to find/collect special coins, and when they do, the coins become semi-transparent, signifying to the player collecting that they already collected this coin and they cannot collect it again. It then adds the found coin to a coin count in a gui at the bottom left corner (It allows them to go from 1/7, 2/7...7/7 kind of like in slender when you need to collect all 7 pages). I have it set under the PlayerGui, however, everyone's gui changes with the person who collects the coins. Instead, I'd like everyone's Coin count in the gui to remain at 0 and the coins to remain opaque until the players collect the coins themselves.
Also, once a player resets, the coins collected remain transparent for all players, but the coin counter resets and goes back to 0, which is not acceptable.
- the script is in StarterGui but it is being called in PlayerGui
- the coins are meshes in the workspace
If anyone knows my problem and knows how to fix it, please do explain. Thank you.
local coinTrack1 = true
local coinTrack2 = true
local coinTrack3 = true
local coinTrack4 = true
local coinTrack5 = true
local coinTrack6 = true
local coinTrack7 = true
local coinNum = 0
player.PlayerGui.CoinTracker.Frame.TextLabel.Text = "Coins "..coinNum.."/7"
game.Workspace.RedCoin1.Touched:Connect(function(hit)
if coinTrack1 == true then
if hit.Parent:WaitForChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
coinNum = coinNum + 1
player.PlayerGui.CoinTracker.Frame.TextLabel.Text = "Coins "..coinNum.."/7"
game.Workspace.RedCoin1.Transparency = .7
coinTrack1 = false
return coinNum
end
end
end)
game.Workspace.RedCoin2.Touched:Connect(function(hit)
if coinTrack2 == true then
if hit.Parent:WaitForChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
coinNum = coinNum + 1
player.PlayerGui.CoinTracker.Frame.TextLabel.Text = "Coins "..coinNum.."/7"
game.Workspace.RedCoin2.Transparency = .7
coinTrack2 = false
return coinNum
end
end
end)
game.Workspace.RedCoin3.Touched:Connect(function(hit)
if coinTrack3 == true then
if hit.Parent:WaitForChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
coinNum = coinNum + 1
player.PlayerGui.CoinTracker.Frame.TextLabel.Text = "Coins "..coinNum.."/7"
game.Workspace.RedCoin3.Transparency = .7
coinTrack3 = false
return coinNum
end
end
end)
game.Workspace.RedCoin4.Touched:Connect(function(hit)
if coinTrack4 == true then
if hit.Parent:WaitForChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
coinNum = coinNum + 1
player.PlayerGui.CoinTracker.Frame.TextLabel.Text = "Coins "..coinNum.."/7"
game.Workspace.RedCoin4.Transparency = .7
coinTrack4 = false
return coinNum
end
end
end)
game.Workspace.RedCoin5.Touched:Connect(function(hit)
if coinTrack5 == true then
if hit.Parent:WaitForChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
coinNum = coinNum + 1
player.PlayerGui.CoinTracker.Frame.TextLabel.Text = "Coins "..coinNum.."/7"
game.Workspace.RedCoin5.Transparency = .7
coinTrack5 = false
return coinNum
end
end
end)
game.Workspace.RedCoin6.Touched:Connect(function(hit)
if coinTrack6 == true then
if hit.Parent:WaitForChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
coinNum = coinNum + 1
player.PlayerGui.CoinTracker.Frame.TextLabel.Text = "Coins "..coinNum.."/7"
game.Workspace.RedCoin6.Transparency = .7
coinTrack6 = false
return coinNum
end
end
end)
game.Workspace.RedCoin7.Touched:Connect(function(hit)
if coinTrack7 == true then
if hit.Parent:WaitForChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
coinNum = coinNum + 1
player.PlayerGui.CoinTracker.Frame.TextLabel.Text = "Coins "..coinNum.."/7"
game.Workspace.RedCoin7.Transparency = .7
coinTrack7 = false
return coinNum
end
end
end)

8 comments
Good idea, but I don't think it will change the transparency problem of the coins only changing for a player who collected it
hmm, you could make it transparent for all players using "player" but change the coin amount using hit.Parent
I'm not sure what you mean, though i am going to accept this answer because I think in order to do this I'll have to create a LocalMesh which I think is a whole other question.
Sorry for not explaining it properly. I mean find the name of the player that touched the coin by doing hit.parent.parent then comparing it to the localPlayers name and if it is the same then change the Gui but if it is different then don't. Then for making it transparent you could detect if it has been hit and just make it transparent for everyone for example
Coin.touchedConnect(function(hit) Coin.Transparency = 0.7
Also I recommend doing something like local Coin1 = game.Workspace.RedCoin1 to make the script shorter
Thank you!
You're welcome :D