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

Multiple wins being awarded, can someone help?

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)

1 comment

0

Is it because there is not wait in between awarding, therefore whenever the player might want to move off the script keep detecting?

1 answer

✓ Accepted answer

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

1 comment

0

Thank you!

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