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 » Scripting Helpers
Home Search
 

How to know if someone is sitting in a seat?

Previous Thread :: Next Thread 
MasterDaniel is not online. MasterDaniel
Joined: 28 Nov 2008
Total Posts: 2866
31 May 2014 10:57 AM
Currently, a script I use uses "hit" to detect when someone sits in a seat. I wanted to know if there was a way to tell if they sat in the seat.

The reason is because my script shows a GUI to any player that isn't VIP, telling them to buy it. It only removes when they get out of the seat, HOWEVER if a person walks past it and touches it without sitting down they will get the GUI and it doesn't disappear.

Heres what I have so far: (not all of the script is here, just the part thats broken)

Seat.Touched:connect(function(hit)
playerHasTouched = 0
if hit and hit.Parent and lookForPlayer(hit.Parent.Name) then
playerHasTouched = 1 -- I tried to detect if the touch happens twice (i.e they are sitting down) but it didn't work
wait(2)
if hit and hit.Parent and lookForPlayer(hit.Parent.Name) then
playerHasTouched = 2
local player = lookForPlayer(hit.Parent.Name)

if (not IsVIP(player)) and Kill_If_Not_VIP and (playerHasTouched == 2) then
script.Parent.Parent.Antiwobble.Anchored = true
script.BuyVIP:clone().Parent = game.Players:findFirstChild(hit.Parent.Name).PlayerGui
wait(10)
script.Parent.Disabled = true
else
script.Parent.Parent.Antiwobble.Anchored = false
script.Parent.Disabled = false
end

playerHasTouched = 0
end
end
end)
Report Abuse
1234Christopher is not online. 1234Christopher
Joined: 21 Oct 2008
Total Posts: 1715
31 May 2014 11:01 AM
if Humanoid.Sit == true then

Then make sure it's the right seat. You can do this by checking the seats.Hit.Parent and the character name of whos sitting.
Report Abuse
MasterDaniel is not online. MasterDaniel
Joined: 28 Nov 2008
Total Posts: 2866
31 May 2014 11:09 AM
Thanks for replying

I changed the first bit to this:

Door.Touched:connect(function(hit)
if Humanoid.Sit==true and seats.hit.Parent and lookForPlayer(hit.Parent.Name) then

but this returns an error with "humanoid" Is this because I haven't declared who the humanoid is? How would I do this?
Report Abuse
XxChopSlaperxX is not online. XxChopSlaperxX
Joined: 09 Nov 2010
Total Posts: 3112
31 May 2014 11:11 AM
function getHumanoidFromPart(part)
if part and part.Parent:FindFirstChild("Humanoid") then
return part.Parent.Humanoid
end
end

local humanoid = getHumanoidFromPart(hit) -- inside the connection

I made it a function so your code doesn't get confusing for you and I believe it's better to give people functions they can use instead of writing it in their code for them.
Report Abuse
1234Christopher is not online. 1234Christopher
Joined: 21 Oct 2008
Total Posts: 1715
31 May 2014 11:13 AM
Loop through the characters to check when the are sitting.
Check if the right character is sitting on right seat.
Then run rest of script.
Report Abuse
MasterDaniel is not online. MasterDaniel
Joined: 28 Nov 2008
Total Posts: 2866
31 May 2014 11:52 AM
I added in the function and then the line of code into the main script so it looks like this:

Seat.Touched:connect(function(hit)
local humanoid = getHumanoidFromPart(script.Parent)
if humanoid.sit==true and seats.hit.Parent and lookForPlayer(hit.Parent.Name) then
local player = lookForPlayer(hit.Parent.Name)
if (not IsVIP(player)) and Kill_If_Not_VIP and not script.Parent.Locked then
script.Parent.Parent.Antiwobble.Anchored = true
script.BuyVIP:clone().Parent = game.Players:findFirstChild(hit.Parent.Name).PlayerGui
wait(10)
script.Parent.Disabled = true
else
script.Parent.Parent.Antiwobble.Anchored = false
script.Parent.Disabled = false
end
end
end)

I get the error that humanoid is a nil value though. I'm not sure if I've incorrectly modified the function or not as the part is script.Parent?
MD

Report Abuse
Gorake is not online. Gorake
Joined: 10 Feb 2014
Total Posts: 219
31 May 2014 11:55 AM
Don't use the Touched event at all - since every time a player sits in a seat a Weld is created, child of the seat, between the seat and the torso, you can exploit the ChildAdded function like so:

seat.ChildAdded:connect(function(child)
if child.Name == "SeatWeld" then
local torso = child.Part1
local character = torso.Parent
local player = game.Players:GetPlayerFromCharacter(character)
--Do whatever
end
end)
Report Abuse
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
31 May 2014 11:57 AM
Doesn't anyone know how seats work?

Seat.ChildAdded:connect(function(w)
if w:IsA("Weld") then
char = w.Part1.Parent
print(char.Name.." is on this seat")
end
end)
Report Abuse
Gorake is not online. Gorake
Joined: 10 Feb 2014
Total Posts: 219
31 May 2014 11:57 AM
Oh, and for when they're getting out of the seat, use DescendantRemoving

seat.DescendantRemoving:connect(function(child)
if child.Name == "SeatWeld" then
local torso = child.Part1
local character = torso.Parent
local player = game.Players:GetPlayerFromCharacter(character)
--Do whatever
end
end)
Report Abuse
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
31 May 2014 11:59 AM
Dang slow connection..
Report Abuse
MasterDaniel is not online. MasterDaniel
Joined: 28 Nov 2008
Total Posts: 2866
31 May 2014 12:03 PM
@gorake

It works! Thank you!
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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