Function not properly running

Hello!
I have been working on a duel system and I can’t figure out why this certain function is not always running.

Here is the function:

player.PlayerGui:WaitForChild("ExitQueue").button.MouseButton1Click:Connect(function()
		if P1 == player.Name then
			exitQueue(player)
		elseif P2 == player.Name then
			exitQueue(player)
		end
	end)

The function runs properly until the player respawns.
Anyone know what the problem is?

Thanks for any help!

You can try disabling ResetOnSpawn for the ScreenGui.

2 Likes

The only thing I can think of is that gui is taking a while to load. Then you should do this:

player:WaitForChild("PlayerGui"):WaitForChild("ExitQueue"):WaitForChild("button").MouseButton1Click...

Assuming this is a LocalScript, you should always wait for the PlayerGui to load in.

local PlayerGui = Player:WaitForChild("PlayerGui")

Thank you so much it worked (characters)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.