local Players = game:GetService("Players")
local player = Players.LocalPlayer
local leaderstats = player:WaitForChild("leaderstats")
local Coin = game.Workspace.AssetsAndModels.Coin
Coin.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
leaderstats.Coins.Value += 1
end
end)
local Players = game:GetService("Players")
local Coin = game.Workspace.AssetsAndModels.Coin
local db = false
Coin.Touched:Connect(function(hit)
if db == true then return end
db = true
if Players:FindFirstChild(hit.Parent.Name) then
local player = Players:FindFirstChild(hit.Parent.Name)
local leaderstats = player:FindFirstChild("leaderstats")
leaderstats.Coins.Value += 1
end
wait(.2)
db = false
end)
I added the db just so it doesn’t add the coin multiple times.
local Players = game:GetService("Players")
local Coin = workspace.AssetsAndModels.Coin
local Debounce = false
Coin.Touched:Connect(function(Hit)
if Debounce then
return
end
Debounce = true
local HitModel = Hit:FindFirstAncestorOfClass("Model")
if HitModel then
local HitPlayer = Players:GetPlayerFromCharacter(HitModel)
if HitPlayer then
HitPlayer.leaderstats.Coins.Value += 1
end
end
task.wait(0.5)
Debounce = false
end)
Previous code looked a little messy. This version will also count touches which occur due to the player’s character’s accessories.