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

Is there a better way of finding out whether the player is still seated?

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

2 comments

0

:remove() is deprecated. Use :destroy() intead.

2 answers

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)

u ever hear of StoppedToucing()? Here or TouchEnded()? Here

1 comment

0

Idiots! -_- He Said, Touch! Not Weld-Detecting!

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