Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Print the name of someone that sits in a seat?

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

✓ Accepted answer
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)

This discussion is preserved as it was. New answers, comments, and votes are closed.