hello. So, I created a script that adds "+1" to the money of the player who touched a coin. apparently, the script is right, but some coins that the player touches (I don’t know if it’s a glitch or something I forgot to put in the script), instead of adding "+1" to your money, a much larger number is added (+3 or +4 ...) script:
local player = game.Players.LocalPlayer player.CharacterAdded:Wait() db = false local cointouchevent = game:GetService("ReplicatedStorage"):WaitForChild("Slotdata"):WaitForChild("CoinDestroy") local hum = player.Character:WaitForChild("Humanoid") pointsvalue = player:WaitForChild("leaderstats"):WaitForChild("Points") local sound = Instance.new("Sound",player.PlayerGui) sound.SoundId = 'rbxassetid://203620899' sound.MaxDistance = 100 sound.Volume = 4 hum.Touched:Connect(function(hit) if hit.Name == "Coin" then if db == false then db = true print("more 1 money") sound:Play() pointsvalue.Value = pointsvalue.Value + 1 hit:Destroy() db = false end end end)
It is as if there was no Debounce (which I put to avoid spam.
Hello. Try using a table. Try this:
local player = game.Players.LocalPlayer player.CharacterAdded:Wait() db = false local cointouchevent = game:GetService("ReplicatedStorage"):WaitForChild("Slotdata"):WaitForChild("CoinDestroy") local hum = player.Character:WaitForChild("Humanoid") pointsvalue = player:WaitForChild("leaderstats"):WaitForChild("Points") local sound = Instance.new("Sound",player.PlayerGui) sound.SoundId = 'rbxassetid://203620899' sound.MaxDistance = 100 sound.Volume = 4 local touchedCoins = {} hum.Touched:Connect(function(hit) if hit.Name == "Coin" then if db == false then db = true for i, v in pairs(touchedCoins) do if v = hit then return nil end end table.insert(touchedCoins, 1, hit) print("Somar money") sound:Play() pointsvalue.Value = pointsvalue.Value + 1 hit:Destroy() db = false end end end) coroutine.wrap(function() while wait(5) do for i = 1, #touchedCoins do table.remove(touchedCoins, i) end end end)
When a coin is touched, it gets inserted into the table. Then every 5 seconds the coin in the touchedCoins array gets removed. Please accept and upvote this answer if it helped.