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

how to get the PlayerGui from a player sitting in a seat?

I'm trying to make a chair that when sat in will make a dialog box appear. (dialog box is done) I know that when you sit in a seat, a weld is created, so, I assumed to do this:

local seat = script.Parent
seat.ChildAdded:Connect(function(player)
	wait(1)
player.Part1.Parent.PlayerGui.chair.Frame.Visible = true
end)

when I used print(player.Part1.Parent) I got my username in the output, so I thought, "hey, I bet that's where the playergui is." But I was wrong. when I put print(player.Part1.Parent.PlayerGui) I got an error that said it wasn't a part of model. I thought maybe it was because it was in a server script, but whenever I put it in a local script the script just does nothing. like no errors or anything. I think it might be because you cant use childadded in a local script but I'm not sure. Any help would be appreciated

1 answer

✓ Accepted answer

Seat.Occupant holds reference to the humanoid value of the character that's sitting in the seat.. just listen for when the property changes, and get the paerent of the humanoid referenced in seat.Occupant then the player associated with that character.

like this:

local seat = --the seat part;
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	if(seat.Occupant) then
		local player = game.Players:GetPlayerFromCharacter(seat.Occupant.Parent);
		if(player) then
			local playerGui = player.PlayerGui
		end
	end
end)

1 comment

0

thanks ;)

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