My coin collection system is broken… It uses a meshpart containing a hitbox to make the coin.
Here’s the script:
local player = game:GetService("Players")
local coin = script.Parent -- Path to coin
local used = false
function giveCoin(part)
if part.Parent:FindFirstChild("Humanoid") == nil or used == true then
return
end
used = true
local player = player:GetPlayerFromCharacter(part.Parent)
player.leaderstats.Candy.Value = player.leaderstats.Candy.Value + 5
coin.Parent:Destroy()
end
coin.Touched:Connect(giveCoin)
Do not paste a script in each coin!
You can easily use collection service and tag to just have 1 script
Put this in server script service:
local collectionService = game:GetService("CollectionService")
local player = game:GetService("Players")
local tag = "coin"
local function newCoin(coin)
coin.Touched:Connect(function(hit)
local player = player:GetPlayerFromCharacter(hit.Parent)
if not player then return end
coin.Parent:Destroy()
player.leaderstats.Candy.Value += 5
end)
end
collectionService:GetInstanceAddedSignal(tag):Connect(newCoin)
for _,v in collectionService:GetTagged(tag) do
newCoin(v)
end
Lol I am so dumb… ofc I forgot to anchor it. Ok so now it does get to the destroy part, but I am not awarded any Candy. Keep in mind I am now using @Hzodx script so it’s different to the original post.
local collectionService = game:GetService("CollectionService")
local player = game:GetService("Players")
local tag = "coin"
local function newCoin(coin)
coin.Touched:Connect(function(hit)
local player = player:GetPlayerFromCharacter(hit.Parent)
if not player then return end
coin.Parent:Destroy()
player.leaderstats.Candy.Value += 5
end)
end
collectionService:GetInstanceAddedSignal(tag):Connect(newCoin)
for _,v in collectionService:GetTagged(tag) do
newCoin(v)
end
more likely that he didn’t tag the coins and they dont work at all
the code is no longer meant to be inside of the coins so destroying it earlier shouldn’t change anything