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
4 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.

local spawns = {
    game.Workspace.Lobby.lobbySpawns.lobbySpawn1.CFrame,
    game.Workspace.Lobby.lobbySpawns.lobbySpawn2.CFrame
    }


script.Parent.Touched:Connect(function(plr)
    local player = game:GetService("Players"):GetPlayerFromCharacter(plr.Parent)
    local debounce = player.Settings.Won.Value
    if debounce == true then
        delay(0, function()
            player.leaderstats.Minicoins.Value = player.leaderstats.Minicoins.Value + 15
            player.leaderstats.MinigameWins.Value = player.leaderstats.MinigameWins.Value + 1
        end)
        local rootPart = plr.Parent:FindFirstChild("HumanoidRootPart")
        rootPart.CFrame = spawns[math.random(1, #spawns)]
        debounce = false
    end
end)
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 — 4y

1 answer

Log in to vote
1
Answered by 4 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:

local spawns = {
game.Workspace.Lobby.lobbySpawns.lobbySpawn1.CFrame,
game.Workspace.Lobby.lobbySpawns.lobbySpawn2.CFrame }


script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local player = game:GetService("Players"):GetPlayerFromCharacter(plr.Parent)
            local debounce = player.Settings.Won.Value
        if debounce == true then
                    player.leaderstats.Minicoins.Value = player.leaderstats.Minicoins.Value + 15
                    player.leaderstats.MinigameWins.Value = player.leaderstats.MinigameWins.Value +1            
            local rootPart = plr.Parent:FindFirstChild("HumanoidRootPart")
            rootPart.CFrame = spawns[math.random(1, #spawns)]
            debounce = false
        end
    end
end)

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 — 4y
Ad

Answer this question