Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to get player from ChildAdded in a seat? (Urgent)

Asked by
Qorm 100
9 years ago

Super cringey question.. How would I get the player from a seat from the ChildAdded function? I tried everything I know and I also researched it but I couldn't find anything.

I also tried using the 'Touched' function for this to get the player (onTouch.Parent) with a debounce etc but that's really not efficient and glitchy. Help would be appreciated!

0
I don't exactly know what you're asking? Are you trying to to something to a player who sits on a Seat? alphawolvess 1784 — 9y
0
Ye, say for example I want to print the person's name sitting in the seat Qorm 100 — 9y

1 answer

Log in to vote
1
Answered by 9 years ago

You can use the ChildAdded and ChildRemoved events as so. I won't go much into explanation, but this is a method you can use:

local plr = nil;
script.Parent.ChildAdded:connect(function(pl)
if not pl:IsA("Weld") then return end
if plr ~= nil then return end
local torso = pl.Part1
local char = torso.Parent
plr = game.Players:GetPlayerFromCharacter(char)
if plr == nil then return end
print("Person Sitting: " .. plr.Name)
end)

script.Parent.ChildRemoved:connect(function (pl)
if not pl:IsA("Weld") then return end
if plr == nil then return end
print("Got Off!")
plr = nil
end)

I learnt this method from 'dr01d3k4's post on it a year or so back.

0
When you sit on a seat, you character becomes welded to said seat. You can see this by sitting and then viewing the children of said seat. There will be a weld. alphawolvess 1784 — 9y
0
Didn't think of getting the parent of HumanoidRootPart from the weld. Thank you kindly! Qorm 100 — 9y
Ad

Answer this question