|
| 06 Aug 2017 10:18 PM |
How would I check if 2 or more players are sitting down on specific seats (theres 4 of them) I want to check so I can start the game.
|
|
|
| Report Abuse |
|
|
| |
|
|
| 06 Aug 2017 10:36 PM |
| http://wiki.roblox.com/index.php?title=API:Class/Seat/Occupant |
|
|
| Report Abuse |
|
|
|
| 06 Aug 2017 10:37 PM |
just asking for the checking if players are sitting on specific seats part not start game
|
|
|
| Report Abuse |
|
|
|
| 06 Aug 2017 10:38 PM |
Thanks, I replied right before I saw that, I'll check it out.
|
|
|
| Report Abuse |
|
|
|
| 06 Aug 2017 10:41 PM |
Okay now, what if 4 seats were in a model located in workspace called Seats And I wanted to check if 2 players were sitting down in any of the 4 seats. How would I go about doing this?
I would know how to do it for 1 seat but not really getting the idea for multiple. Thanks!
|
|
|
| Report Abuse |
|
|
|
| 06 Aug 2017 11:04 PM |
local seats = workspace.Seats:GetChildren() seats.Changed:connect(function(property) if property ~= 'Occupant' then return end local occupant = seats.Occupant if occupant then local character = occupant.Parent local player = game.Players:GetPlayerFromCharacter(character) if player then print(("Player %q just sat on the seat"):format(player.Name)) else print(("NPC %q just sat on the seat"):format(character.Name)) end else print("Someone left the seat") end end)
ServerScriptService.Script:2: attempt to index field 'Changed' (a nil value) I get this error
|
|
|
| Report Abuse |
|
|
|
| 06 Aug 2017 11:26 PM |
wrap that in a
for i,v in pairs(seats) do v.Changed:Connect(property) |
|
|
| Report Abuse |
|
|
|
| 07 Aug 2017 12:10 PM |
This just printed 4 "Player has left the seat"
local seats = workspace.Seats:GetChildren() for i,v in pairs(seats) do v.Changed:Connect(function(property) if property ~= 'Occupant' then return end end) local occupant = seats.Occupant if occupant then local character = occupant.Parent local player = game.Players:GetPlayerFromCharacter(character) if player then print(("Player %q just sat on the seat"):format(player.Name)) else print(("NPC %q just sat on the seat"):format(character.Name)) end else print("Someone left the seat") end end Did i do something wrong especially with the amount of ends I put and how I put them?
|
|
|
| Report Abuse |
|
|
Exzeption
|
  |
| Joined: 01 Nov 2011 |
| Total Posts: 1312 |
|
|
| 07 Aug 2017 12:16 PM |
you ended the function before it checked the seats
|
|
|
| Report Abuse |
|
|
|
| 07 Aug 2017 12:18 PM |
local seats = workspace.Seats:GetChildren() for i,v in pairs(seats) do v.Changed:Connect(function(property) if property ~= 'Occupant' then return end local occupant = seats.Occupant if occupant then local character = occupant.Parent local player = game.Players:GetPlayerFromCharacter(character) if player then print(("Player %q just sat on the seat"):format(player.Name)) else print(("NPC %q just sat on the seat"):format(character.Name)) end else print("Someone left the seat") end end)
I don't know where to put the last end :p
|
|
|
| Report Abuse |
|
|
Exzeption
|
  |
| Joined: 01 Nov 2011 |
| Total Posts: 1312 |
|
|
| 07 Aug 2017 12:37 PM |
| second to last end needs a parenthesis,last one does not |
|
|
| Report Abuse |
|
|
|
| 07 Aug 2017 12:39 PM |
Tried that and then got "player has left the seat" in the prints print(("Player %q just sat on the seat"):format(player.Name))
that doesn't print
|
|
|
| Report Abuse |
|
|
| |
|
| |
|
|
| 07 Aug 2017 03:03 PM |
local seats = workspace.seats:GetChildren() local seated = script.Value --best way I can think of to do this is with an IntValue, to avoid using while loops
for i,v in pairs(seats) do v:GetPropertyChangedSignal("Occupant"):Connect(function() local occupant = v.Occupant if occupant then seated.Value = seated.Value + 1 local character = occupant.Parent local player = game.Players:GetPlayerFromCharacter(character) if player then print(("Player %q just sat on the seat"):format(player.Name)) else print(("NPC %q just sat on the seat"):format(character.Name)) end else seated.Value = seated.Value - 1 print("Someone left the seat") end end) end
seated:GetPropertyChangedSignal("Value"):Connect(function() if seated.Value >= 2 then print(seated.Value) end end) |
|
|
| Report Abuse |
|
|
| |
|