generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: How would I do this?

Previous Thread :: Next Thread 
Randy_Moss is not online. Randy_Moss
Joined: 05 Aug 2009
Total Posts: 30511
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
Randy_Moss is not online. Randy_Moss
Joined: 05 Aug 2009
Total Posts: 30511
06 Aug 2017 10:27 PM
B


Report Abuse
systematicaddict is not online. systematicaddict
Joined: 13 Jul 2012
Total Posts: 4188
06 Aug 2017 10:36 PM
http://wiki.roblox.com/index.php?title=API:Class/Seat/Occupant
Report Abuse
Randy_Moss is not online. Randy_Moss
Joined: 05 Aug 2009
Total Posts: 30511
06 Aug 2017 10:37 PM
just asking for the checking if players are sitting on specific seats part not start game


Report Abuse
Randy_Moss is not online. Randy_Moss
Joined: 05 Aug 2009
Total Posts: 30511
06 Aug 2017 10:38 PM
Thanks, I replied right before I saw that,
I'll check it out.


Report Abuse
Randy_Moss is not online. Randy_Moss
Joined: 05 Aug 2009
Total Posts: 30511
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
Randy_Moss is not online. Randy_Moss
Joined: 05 Aug 2009
Total Posts: 30511
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
systematicaddict is not online. systematicaddict
Joined: 13 Jul 2012
Total Posts: 4188
06 Aug 2017 11:26 PM
wrap that in a

for i,v in pairs(seats) do
v.Changed:Connect(property)
Report Abuse
Randy_Moss is not online. Randy_Moss
Joined: 05 Aug 2009
Total Posts: 30511
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 is not online. 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
Randy_Moss is not online. Randy_Moss
Joined: 05 Aug 2009
Total Posts: 30511
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 is not online. 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
Randy_Moss is not online. Randy_Moss
Joined: 05 Aug 2009
Total Posts: 30511
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
Randy_Moss is not online. Randy_Moss
Joined: 05 Aug 2009
Total Posts: 30511
07 Aug 2017 01:09 PM
hmm


Report Abuse
Randy_Moss is not online. Randy_Moss
Joined: 05 Aug 2009
Total Posts: 30511
07 Aug 2017 01:45 PM
B


Report Abuse
systematicaddict is not online. systematicaddict
Joined: 13 Jul 2012
Total Posts: 4188
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
Randy_Moss is not online. Randy_Moss
Joined: 05 Aug 2009
Total Posts: 30511
07 Aug 2017 03:07 PM
Thanks system!


Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image