Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

The points i give to player are multiplicated !! ?

When i touched the part the coins are multiplicated and i just want to give them 10 coins but the game can like give 140 coins !!! :(

local lobbyTP = game.Workspace.Lobby.TeleportFinishedParkour

script.Parent.Touched:Connect(function(part)
    for _, plr in ipairs(game:GetService("Players"):GetPlayers()) do
        plr.Character:SetPrimaryPartCFrame(lobbyTP.CFrame)
		plr.Stats.Coins.Value = plr.Stats.Coins.Value + 10
    end
end)

3 comments

1

The reason for this is because the Touched event is being triggered multiple times. Add a debounce or some sort of characterIgnoreList to fix this.

1

This would give all players + 10 ?

0

only the player who touch it !

1 answer

You aren't adding a debounce to prevent the player from getting more than the desired coins

-- also, if you want to give it to one player, don't use a for loop like you did, as that'll give to ALL players

local lobbyTP = workspace.Lobby.TeleportFinishedParkour
local debounce = false

script.Parent.Touched:Connect(function(part)
       local plr = game.Players:GetPlayerFromCharacter(part.Parent)
       if plr and not debounce then
              debounce = true
              plr.Character:SetPrimaryPartCFrame(lobbyTP.CFrame)
              plr.Stats.Coins.Value = plr.Stats.Coins.Value + 10
              wait(2)
              debounce = false
       end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.