Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Help Preventing More Than 1 Screen Gui?

Asked by 9 years ago

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

Log in to vote
1
Answered by
Tkdriverx 514 Moderation Voter
9 years ago

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)
0
Thanks! That was exactly what I needed! Thank you!!! :D:D kieranm9090 49 — 9y
Ad

Answer this question