The following script goes into a seat.
local debounce = false function onTouched(part) local player = part.Parent if debounce == false then debounce = true print("Debounce is On") end wait() gui = Instance.new("ScreenGui") local textbox = Instance.new("TextBox") local plr = Workspace.Parent.Players:FindFirstChild(player.Name) gui.Parent = plr.PlayerGui gui.Name = "TrainGui" textbox.Name = "TrainGui" textbox.Parent = gui textbox.Text = "Testing" textbox.BackgroundTransparency = 1 textbox.Position = UDim2.new(0.5, 0, 0.2, 0) wait(0.5) if not script.Parent:FindFirstChild("SeatWeld")then print("Seat Weld has been lost") gui:Remove() print("Gui Removed?") end debounce = false end script.Parent.Touched:connect(onTouched)
Sometimes 'Gui Removed?' gets printed but the gui that says testing is not removed and on other times it doesn't appear at all.
Is there a better way of finding out whether the player is still seated or is there something wrong in the script itself? ._.
Sorry if there's a rookie mistake somewhere here
local Seat = script.Parent local Player = nil Seat.ChildAdded:connect(function(Child) --This event fires when a child is added to the seat if Child.Name == "SeatWeld" then --If the child's name is "SeatWeld"... Player = game.Players:GetPlayerFromCharacter(Child.Part1.Parent) --Get's the player from the SeatWeld if Player then --If the person seated is a legitimate player... --Code here end end end) Seat.ChildRemoved:connect(function(Child) --This event fires when a child is removed from the seat if Child.Name == "SeatWeld" then --If the child was the SeatWeld... if Player then --If the player still exists... --Code here end end end)