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

Multiple wins being awarded, can someone help?

Asked by
harstud 218 Moderation Voter
5 years ago

I've tried debounce, it didn't work. Whenever a player touches the win area, it's meant to give them the amount of coins the person who edited the script of what they wanted and 1 win. It keeps giving double or even MORE than double amount. Please, someone fix my script.

01local spawns = {
02    game.Workspace.Lobby.lobbySpawns.lobbySpawn1.CFrame,
03    game.Workspace.Lobby.lobbySpawns.lobbySpawn2.CFrame
04    }
05 
06 
07script.Parent.Touched:Connect(function(plr)
08    local player = game:GetService("Players"):GetPlayerFromCharacter(plr.Parent)
09    local debounce = player.Settings.Won.Value
10    if debounce == true then
11        delay(0, function()
12            player.leaderstats.Minicoins.Value = player.leaderstats.Minicoins.Value + 15
13            player.leaderstats.MinigameWins.Value = player.leaderstats.MinigameWins.Value + 1
14        end)
15        local rootPart = plr.Parent:FindFirstChild("HumanoidRootPart")
16        rootPart.CFrame = spawns[math.random(1, #spawns)]
17        debounce = false
18    end
19end)
0
Is it because there is not wait in between awarding, therefore whenever the player might want to move off the script keep detecting? speedyfox66 237 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

So at line 7, you didn't specify if the thing that the thing that touched the script's parent is a PLAYER. It could be a basepart, or something else. Then at line 8, you tried to get the players with the name of the parent of hit (you wrote player). But the name of the parent of hit (you wrote player) could also be the basepart or another object. You should do this:

01local spawns = {
02game.Workspace.Lobby.lobbySpawns.lobbySpawn1.CFrame,
03game.Workspace.Lobby.lobbySpawns.lobbySpawn2.CFrame }
04 
05 
06script.Parent.Touched:Connect(function(hit)
07    if hit.Parent:FindFirstChild("Humanoid") then
08        local player = game:GetService("Players"):GetPlayerFromCharacter(plr.Parent)
09            local debounce = player.Settings.Won.Value
10        if debounce == true then
11                    player.leaderstats.Minicoins.Value = player.leaderstats.Minicoins.Value + 15
12                    player.leaderstats.MinigameWins.Value = player.leaderstats.MinigameWins.Value +1           
13            local rootPart = plr.Parent:FindFirstChild("HumanoidRootPart")
14            rootPart.CFrame = spawns[math.random(1, #spawns)]
15            debounce = false
16        end
17    end
18end)

Also, I don't know why you added that function (delay) at line 11. Try this script, I'm sure it will work!

Hope this helped

0
Thank you! harstud 218 — 5y
Ad

Answer this question