Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

The points i give to player are multiplicated !! ?

Asked by 5 years ago
Edited 5 years ago

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)
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. ScrewDeath 153 — 5y
1
This would give all players + 10 ? User#5423 17 — 5y
0
only the player who touch it ! LinkeeReiss 10 — 5y

1 answer

Log in to vote
2
Answered by
Rare_tendo 3000 Moderation Voter Community Moderator
5 years ago

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)
Ad

Answer this question