Welcome to the Forums!
Join thousands of other Roblox members with a free account.
Create Forum Account

Help with SeatPart

  • This website was created by Roblox members to replace the official forums (because Roblox shut them down) Join us if you like Roblox!
Status
Not open for further replies.

Volatile

New Member
Reputation: 0 / 0 / 0
Jul 22, 2020
3
0
1
Roblox
Volatile
local seat = game.Workspace.Test

local function Test(otherPart)

local Humanoid = otherPart.parent:FindFirstChild("Humanoid")

print(Humanoid.Parent)

print(Humanoid.SeatPart)

if Humanoid.SeatPart == "Test" then

print("it worked")

end

end

seat.touched:Connect(Test)

This will print the Humanoid.part name but this hangs on the If statement check if it matches Test. what is the issue here?
 

WizardOfHills

Active Member
Reputation: 1 / 0 / 0
Jul 21, 2018
579
7
112
43
Roblox
WizardOfHills
Docs are here. SeatPart is an Instance, not a name / string.

Also I would not expect seat to capture the character so instantaneously that in callback to Touched it will be already seated. You may wish to add wait(0.1).
 
  • Like
Reactions: Volatile

Volatile

New Member
Reputation: 0 / 0 / 0
Jul 22, 2020
3
0
1
Roblox
Volatile
Hi WizardOfHills,

So is there any way to accomplish this? I need to validate that SeatPart is a certain name when humanoid is sitting in it.
 

CallMeKY

Moderator
Ultra
Reputation: 6 / 0 / 0
Feb 25, 2018
1,464
32
591
113
Maine, USA
Roblox
CallMeKY
Discord
CallMeKY#5012
local seat = game.Workspace.Test

local function Test(otherPart)

local Humanoid = otherPart.parent:FindFirstChild("Humanoid")

print(Humanoid.Parent)

print(Humanoid.SeatPart)

if Humanoid.SeatPart == "Test" then

print("it worked")

end

end

seat.touched:Connect(Test)

This will print the Humanoid.part name but this hangs on the If statement check if it matches Test. what is the issue here?
So is there any way to accomplish this? I need to validate that SeatPart is a certain name when humanoid is sitting in it.


When a player sits in a seat, the Occupant property changes. You can connect to that property with GetPropertyChangedSignal. You can get the name of the seat with Seat.Name or tostring(Seat).
Lua:
local seat = workspace:WaitForChild('Test')

seat:GetPropertyChangedSignal('Occupant'):Connect(function() -- connect to this to fire every time the property changes
    if not seat.Occupant then return end -- if there is no occupant, the property will be nil
    print(seat.ClassName .. ' "' .. tostring(seat) .. '" is occupied by ' .. tostring(seat.Occupant.Parent)) -- the occupant property will be the humanoid
end)
 

Volatile

New Member
Reputation: 0 / 0 / 0
Jul 22, 2020
3
0
1
Roblox
Volatile
Thanks for the help Guys.

I think the .Name has solved it. I swear I tried that.

Lua:
local seat = Humanoid.SeatPart

print (seat.Name)

    if seat.Name == "Test" then
 
Status
Not open for further replies.