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

Help Preventing More Than 1 Screen Gui?

Hi,

I have made this script for my seat to give a person a Screen GUI. But then I forgot that every time I go into the seat it will give me the GUI again. What do I have to put in to make it so that the next time I sit in the seat with the GUI already on my screen, it does not give me the GUI again? Please bear in mind that I want to have the GUi on my screen when I leave the seat also.

Script:

seat = script.Parent.Seat
gui = script.Parent.MyGui


seat.ChildAdded:connect(function(newWeld)
	character = newWeld.Part1.Parent
	player = game.Players:GetPlayerFromCharacter(character)
	if player.Backpack:FindFirstChild("Staff") then
		guiClone = gui:Clone()
		guiClone.Parent = player.PlayerGui
	end
end)

Thanks Kieran

1 answer

✓ Accepted answer

All you need to do is check if it exists already.

seat = script.Parent.Seat
gui = script.Parent.MyGui

seat.ChildAdded:connect(function(newWeld)
	lcoal character = weld.Part1.Parent
	local player = game.Players:playerFromCharacter(character)
	if player.Backpack:FindFirstChild("Staff") then
		if player.PlayerGui:findFirstChild(gui.Name) then return end -- This checks if there is one already. If it exists, it returns, and end the function call. If it doesn't exist, it continues.
		guiClone = gui:Clone()
		guiClone.Parent = player.PlayerGui
	end
end)

1 comment

0

Thanks! That was exactly what I needed! Thank you!!! :D:D

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