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.
01 | local spawns = { |
02 | game.Workspace.Lobby.lobbySpawns.lobbySpawn 1. CFrame, |
03 | game.Workspace.Lobby.lobbySpawns.lobbySpawn 2. CFrame |
04 | } |
05 |
06 |
07 | script.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 |
19 | end ) |
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:
01 | local spawns = { |
02 | game.Workspace.Lobby.lobbySpawns.lobbySpawn 1. CFrame, |
03 | game.Workspace.Lobby.lobbySpawns.lobbySpawn 2. CFrame } |
04 |
05 |
06 | script.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 |
18 | 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