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

how do you detect if the player has sit on a seat on a server script?

i have been on this for hours now so basically i got this table here with all the seat local Seats = { workspace["Model [2] Alpha Series of Main Battery Class"].Seat --and so on repeat } there is only one cuz i want to keep things simple and also it wouldnt change if i put all of my seats in the table

and this for loop loops through the table and see if player is sitting on one of these seats

if player is sitting on one of these seats in the table then it will print ok so i know the script is working but the script does not print ok and didnt error so i dont know whats wrong

for i, Seat in pairs(Seats) do
	if Seat.Occupant ~= nil then
		print("ok") -- it just wont work
	else
		print("no")
	end
end

im planning to use this to parent a remote event to rep storage when i get these print statements to work

a local script will be waiting to use that same remote event to transfer some important data that most likely is needed to parent the remote event back to server storage

3 comments

0

when a player sits on the seat, a new weld called SeatWeld is made in the seat so then you can use it to know when a player sits

0

oh ya and it only runs once so then thats why it wont work

0

thanks your tip helped me found a fix

2 answers

i found answer myself

edit: after a bit of testing and more research i found something that will work and is less complex

local Seats = {
	
	workspace["Model [2] Alpha Series of Main Battery Class "].Seat,
	
	workspace["Model [2] Bravo Series of Main Battery Class "].Seat,
	
	workspace["Model [3] Charlie Series of Main Battery Class "].Seat
	
}

for i, Seat in pairs(Seats) do
	local RemoteEvent = game.ServerStorage.RemoteEvent
	Seat.Changed:Connect(function(Properties)
		if Seat.Occupant ~= nil then
			RemoteEvent.Parent = game.ReplicatedStorage
		elseif Properties == "Occupant" and Seat.Occupant == nil then
			RemoteEvent.Parent = game.ServerStorage
		end
	end)
end

I’m sorry that this comment has nothing to do with this section, but I have been trying to post a question: “Why won’t my if statement run”, but it says “your question could not be posted because the title is too long”. I even changed the title to “if statement” and it still would not work!

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