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

Script that tracks how many players sit in a seat?

hello, how do I make a script that can track how many players are sitting in seats? So like if I had a text label it would start off as 0/10 and when someone sits in a seat it increases in 1/10 and when someone jumps it decreases back to 0.

  • I've tried a lot of things but this just has me stumped.

2 comments

0

You can question this on the developer forum because this question from my POV is just a request.

1 answer

Here is an idea, maybe you could make it so that if a player is added to a seat, a variable would add 1 to it. and if the number was 10, it could start. the only thing is that it would probably have to be a global variable. I have no idea how to detect an occupant, but here is an example I think should work:

_G.playersinseats = 0 --_G means that it is a global variable I think, Which means that it can be accessed anywhere.
if script.Parent.Occupant != nil then
	print(script.Parent.Occupant)
	_G.playersinseats = _G.playersinseats + 1
end

sorry if this does not help, I have never answered a question before. EDIT: Here is a better script:

_G.playersinseats = 0 --_G means that it is a global variable I think, Which means that it can be accessed anywhere.
script.Parent.OccupantChanged:Connect(function()
if script.Parent.Occupant != nil then
	print(script.Parent.Occupant)
	_G.playersinseats = _G.playersinseats + 1
end
end

2 comments

0

not equals to is ~= in lua

0

You shouldn't answer questions when you don't know how to solve it. I'm unsure why you're using _G? Your just doing it in 1 script

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