The question is pretty easy to understand.
In a game, I have a seat and nothing will happen until they sit in it. But if they want to hop off the seat, they cannot, because they will be stuck.
I need to know how to detect when the player sits, and how to keep them in the seat.
local hum = script.Parent.Humanoid
hum.Sit:GetPropertyChangedSignal("Value"):Connect(function()
if hum.Sit.Value == true then
hum.JumpPower = 0
end
end)
You can do this a couple of ways, by checking the property Occupant of the seat itself, check the SeatPart of the players Character, or use @OIogist way.
Seat Script Example:
local Seat = script.Parent -- Path to seat
Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
if Seat.Occupant ~= nil then
local Char = Seat.Occupant.Parent
Char["HumanoidRootPart"].Anchored = true
-- Can also set their jump power if wanting, your preference
end
end)
You should use âhum.Sit == trueâ not âhum.Sit.Value == trueâ
local hum = script.Parent.Humanoid
hum:GetPropertyChangedSignal("Sit"):Connect(function()
if hum.Sit == true then
hum.JumpPower = 0
end
end)
EDIT: I realized that it will detect if u seat but it doesnât specify a seat so I will add that code soon also ignore the ââ'hum.JumpPower = 0", itâs not needed
hello, I need some help with something.
I want to make it so that if a humanoid is in a seat, a GUI appears on the screen and if they leave the seat it disappears.
here is my code:
local DriverSeat = script.Parent
local function Seated()
if DriverSeat.Occupant ~= nil then
end
end
DriverSeat:GetPropertyChangedSignal(âOccupantâ):Connect(Seated)
hello, so first to make the gui appear you need to add the code inside the if statement, i cant write the code because i donât know if the gui is a screen gui or frameâŠ>
second you need to add another if hat detects if the driverseat.occupant == nil(player left) so you can remove the gui when the player leaves hereâs how the code will be:
local DriverSeat = script.Parent
local function Seated()
if DriverSeat.Occupant ~= nil then
-- code to make the gui appear
end
if DriverSeat.Occupant == nil then
--code to make the gui disappear
end
end
DriverSeat:GetPropertyChangedSignal(âOccupantâ):Connect(Seated)
now if the code doesnât work resend the script with its location in the explorer because i have a bug in mind but it might work
To add on to this, I find it works best if I do anything related to sitting in one script under ServerScriptService, like so:
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
local humanoid = character:FindFirstChild("Humanoid")
humanoid:GetPropertyChangedSignal("Sit"):Connect(function()
if humanoid.Sit then
player:SetAttribute("IsSitting", true)
else
player:SetAttribute("IsSitting", false)
end
end)
end)
end)
This easily finds the player, character, and humanoid. The reason I use an attribute and not a local boolean variable is so that I can easily access it from other scripts, if needed, using :GetAttributeChangedSignal("IsSitting").
I want the gui to only appear on the player who is seated
Can you help?
Here is my code:
local Passpart = game.Workspace.PassPart
local prox = Passpart.ProximityPrompt
prox.Triggered:Connect(function(plr)
if plr.Backpack:FindFirstChild("Pasaport") then
print("Pasaport Bulundu!")
local Seat = game.Workspace.SMSEAT
local function Seated()
if Seat.Occupant ~= nil then
game.StarterGui["Pasaport Gui"].Passaport.Visible = true
end
if Seat.Occupant == nil then
game.StarterGui["Pasaport Gui"].Passaport.Visible = false
end
end
Seat:GetPropertyChangedSignal("Occupant"):Connect(Seated)
else
print("Pasaport Bulunamadı")
end
end)