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

Print the name of someone that sits in a seat?

Asked by
lucas4114 607 Moderation Voter
8 years ago

So, someone sits in a seat and the script prints the name in the output... It doesn't work, I'm making this so I can use it for a car later...

function OnSit()
    local Character = script.Parent.Occupant
    local Player = Character.Parent:GetPlayerFromCharacter()
    print(Player)
end

script.Parent.Changed:connect(OnSit)

Output says, when a player sits in a seat: "09:49:27.577 - GetPlayerFromCharacter is not a valid member of Model", And when a player gets out of the seat: "09:49:35.489 - Workspace.Model.Seat.Script:4: attempt to index local 'Character' (a nil value)"

1 answer

Log in to vote
2
Answered by 8 years ago
function OnSit()
    local Character = script.Parent.Occupant
    local Player = Game.Players:GetPlayerFromCharacter(Character.Parent) --When using :GetPlayerFromCharacter(), the Character model goes inside the parenthesis.
    print(Player)
end

script.Parent.Changed:connect(OnSit)

Ad

Answer this question