I got a coin system thats super bugged out, it only works 75% of the time and i need HELP
I cant find whats wrong here
----- | Services | -----
local Players = game:GetService("Players")
----- | Variables | -----
WaitTime = 300
Amount = 75
Debounce = false
----- | Method | -----
function onTouch(part)
if not Debounce then Debounce = true
local Human = part.Parent:FindFirstChild("Humanoid")
if Human then
local Player = Players:GetPlayerFromCharacter(Human.Parent)
if Player then
local leaderStat = Player:FindFirstChild("leaderstats") :FindFirstChild("EggCoins")
if leaderStat then
leaderStat.Value += Amount
end
end
script.Parent.Music:Play()
script.Parent.Day.Enabled = true
script.Parent.Transparency = 1
task.wait(1.25)
script.Parent.Day.Enabled = false
script.Disabled = true
task.wait(WaitTime)
script.Parent.Transparency = 0
script.Disabled = false
Debounce = false
end
end
end
----- | Callback | -----
script.Parent.Touched:Connect(onTouch)
What is the problem you are experiencing? Are the coins not being picked up?
I would not recommend using one scro[t per coin either. It looks like that is what you are doing.
Basically when the player touches the coin confetti comes up with a sound and updates the leaderstat value, Problem is 25% of the time the coin script doesn’t work and when i touch it nothing updates orhappens
Maybe it’s because the scripting has errors, causing the coins not to be picked up, but I recommend fixing some errors by finding errors in the script, that caused it not to be collected or picked up.
I agree, since we have to raycast to collect the coins to fix the bug, so that’s why .Touched doesn’t work as always, I agree with the idea of creating a hitbox, and that’s why it might help fix the bug as a resolution.
A Hitbox is very simple. Just create a Part you want the Touched Event to be fired in, and have it surround the entire coin, Alternatively, a Region3 would work too.
There are plenty of tutorials that show you how to raycast.