Here is the script for a coin collecting
local coin = workspace.Coin coin.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid")then local player = game.Players:GetPlayerFromCharacter(hit.Parent) player.Leaderstats["Coins"].Value = player.Leaderstats["Coins"].Value + 1 coin:Destroy() end end)
However there is no other collectable coin besides the only one. They all have the same name. Anyone has a idea how can i fix this or improve my script?
Assuming you have one script controlling all of the coins, you are only defining one coin, in which case all the others are left alone. To fix this, you can make a folder in your workspace named something like "CoinStorage" and throw all your coins in there, and reference them by using the function :GetChildren() Here's an example of how this could be done:
local coins = workspace.CoinStorage:GetChildren() -- "CoinStorage" is a folder in the workspace containing all of the coins for i = 1, #coins do local coin = coins[i] coin.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent) player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 1 coin:Destroy() end end) end
Hope this helps!