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

How would i make it so when a player sits in a seat a gui pops up only for them?

here is my code

				plr.PlayerGui.Join.Enabled = true
				wait(3)
				plr.PlayerGui.Join.Enabled = false

Which works just fine but it displays for everyone,

This is used in a regular script not local script. even when i use

game.ReplicatedStorage.Local:FireClient(plr)

in replace of the previous code

then add a local script with

game.ReplicatedStorage.Local.OnClientEvent:Connect(function(plr)
	local player = game.Players.LocalPlayer
	player.PlayerGui.Join.Enabled = true
	wait(3)
	player.PlayerGui.Join.Enabled = false
end)

it still displays for everyone. please let me know why

1 answer

✓ Accepted answer

You're supposed to check if the variable plr is the same as player.

Here's a better way to do it:

local Players = game:GetService("Players")
local seat, gui = workspace.Seat, workspace.Seat.gui -- your path

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	local humanoid = seat.Occupant

	if humanoid then
		local player = Players:GetPlayerFromCharacter(humanoid.Parent)
		local guiClone = gui.Clone()
		guiClone.Parent = player.PlayerGui
		game:GetService("DebrisService"):AddItem(guiClone, 3)
	end
end)

What this does is checks when the Occupant property for a seat changes and checks if there is a player in the seat if there is it will clone a gui to the player.

Make sure the Gui is already enabled.

2 comments

0

This goes in a server script. I make no guarantee for whether this code will work or not. But you should be able to tweak it to work.

0

Thank you so much :)

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