How to set the occupant of a seat

So I am making this in a client script and you can’t use :Sit on client so I made this:

local VehicleSeat = script.Parent.Parent
local FlyPrompt = VehicleSeat:WaitForChild("FlyPrompt")

local function Sit(player)
	local character = player.Character
	local humanoid = character:WaitForChild("Humanoid")
	local HumanoidRootPart = character:WaitForChild("HumanoidRootPart")
	
	local weld = Instance.new("Weld")
	weld.Part0 = HumanoidRootPart
	weld.Part1 = VehicleSeat
	weld.Parent = HumanoidRootPart
	
	humanoid.Sit = true
end

FlyPrompt.Triggered:Connect(function(player)
	Sit(player)
end)

VehicleSeat:GetPropertyChangedSignal("Occupant"):Connect(function()
	if VehicleSeat.Occupant then
		FlyPrompt.Enabled = false
	else
		FlyPrompt.Enabled = true
	end
end)

But now there is a problem because the occupant would still be nil so how can I set the occupant to the humanoid?

I did it wrong!

local VehicleSeat = script.Parent
local FlyPrompt = VehicleSeat:WaitForChild("FlyPrompt")

local function Sit(player)
	local character = player.Character
	local humanoid = character:WaitForChild("Humanoid")
	local HumanoidRootPart = character:WaitForChild("HumanoidRootPart")
	
	humanoid.Sit = true
	
	local weld = Instance.new("Weld")
	weld.Name = "SeatWeld"
	weld.Part0 = VehicleSeat
	weld.Part1 = HumanoidRootPart
	weld.C0 = CFrame.new(0, 0.5, 0)
	weld.C1 = CFrame.new(0, -1.5, 0)
	weld.Parent = VehicleSeat
end

FlyPrompt.Triggered:Connect(function(player)
	Sit(player)
end)

VehicleSeat:GetPropertyChangedSignal("Occupant"):Connect(function()
	if VehicleSeat.Occupant then
		FlyPrompt.Enabled = false
	else
		FlyPrompt.Enabled = true
	end
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.