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

Why do I have to sit twice for the GUI to show up?

Asked by 3 years ago

The script is inside the VehicleSeat, but I have to sit twice in order for the GUI to show up.

local ui = script.Parent:FindFirstChild("PoliceGUI")

script.Parent.Touched:connect(function(hit)
    if hit.Parent ~= nil then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        if hit.Parent:FindFirstChild("Humanoid") ~= nil then
            hit.Parent.Humanoid.Seated:connect(function(active, seat)
                if player ~= nil then
                    if active == true and seat == script.Parent then
                        if player.PlayerGui:FindFirstChild("PoliceGUI")== nil then
                            ui:Clone().Parent = player.PlayerGui
                            print("seated")
                        end
                    elseif active ~= true and seat ~= script.Parent then
                        if player.PlayerGui:FindFirstChild("PoliceGUI") ~= nil then
                            player.PlayerGui:FindFirstChild("PoliceGUI"):Destroy()
                            print("not seated")
                        end
                    end
                end
            end)
        end
    end
end)

2 answers

Log in to vote
1
Answered by 3 years ago
Edited 3 years ago

Remake of script:


--[[ Services ]]-- local Players = game:GetService("Players") --[[ Instances ]]-- local Seat = script.Parent local UI = Seat:FindFirstChild("PoliceGUI") --[[ Variables ]]-- local Player --[[ Events ]]-- Seat:GetPropertyChangedSignal("Occupant"):Connect(function() if Player then if Player.PlayerGui:FindFirstChild("PoliceGUI") then Player.PlayerGui.PoliceGUI.Visible = false end end if Players:GetPlayerFromCharacter(Seat.Occupant) then Player = Players:GetPlayerFromCharacter(Seat.Occupant) if not Player.PlayerGui:FindFirstChild("PoliceGUI") then UI:Clone().Parent = Player.PlayerGui end Player.PlayerGui.PoliceGUI.Visible = true end end)

Explanation coming later,

0
It didn't work Gam3r_Play3r 47 — 3y
0
What didn't work User#30567 0 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

Is it possible the PoliceGui is already inside the PlayerGui but invisible? Do a double check and make sure PoliceGui isn't already in StarterGui.

0
Change to comment pls User#30567 0 — 3y
0
It's not in the StarterGui, it's in the VehicleSeat Gam3r_Play3r 47 — 3y

Answer this question