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

I'm trying to make a frame visible when you sit on a seat and when your not sitting, it goes away?

Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
    if Seat.Occupant == nil then 
        frame.Visible = false
        return
    end
    frame.Visible = true
end)

sorry for the title i had to get it below 100 letters

2 answers

You should be using a RemoteEvent. For the example, it will be under ReplicatedStorage:

Server Script:


Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
    if Seat.Occupant ~= nil then 
        local player = game.Players:GetPlayerFromCharacter(Seat.Occupant.Parent)
        game.ReplicatedStorage.RemoteEvent:FireClient(player)
    end    
end)

Local Script (Child of StarterGUI):

game.ReplicatedStorage.OnClientEvent:Connect(function()
    frame.Visible = true
end)

2 comments

0

You don't have to use a RemoteEvent.

0

what’s the alternative? Accessing the PlayerGUI?

You do not need a RemoteEvent for this. It's an absolute waste of time. This can all be done from the client and the server doesn't have to do anything.

The property that will most certainly do you good is Humanoid.SeatPart. This will give you the part the Humanoid is sitting in, if the Humanoid's current state is Sitting and the state change was not initiated outside of a Seat.

You can call GetPropertyChangedSignal() and detect when the SeatPart is not nil:

game.Players.LocalPlayer.CharacterAdded:Connect(function(char)
	local hum = char.Humanoid
	hum:GetPropertyChangedSignal("SeatPart"):Connect(function()
		if hum.SeatPart then -- If SeatPart isn't nil, then move to the next line
			print(hum.SeatPart.Name) -- Print the name of the SeatPart
		end
	end)
end)

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