How can i get the humanoid from a server script?

The title explains itself all i want to do is get the humanoid and change the bodyheightscale, but it seems complicated enough to everything i do is wrong

local proximityPrompt = script.Parent
local seat = proximityPrompt.Parent

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	if seat.Occupant then
		local Humanoid = player.Character:WaitForChild("Humanoid")
		local BHS = Humanoid.BodyHeightScale
		BHS.Value = 1
		proximityPrompt.Enabled = false
		seat.Parent.Body.Seat.SeatFR.ProximityPrompt.Enabled = false
		seat.Parent.Body.Seat.SeatRL.ProximityPrompt.Enabled = false
		seat.Parent.Body.Seat.SeatRR.ProximityPrompt.Enabled = false
		seat.Parent.Body.Smoke.ParticleEmitter.Enabled = true
	else
		local Humanoid = player.Character:WaitForChild("Humanoid")
		local BHS = Humanoid.BodyHeightScale
		BHS.Value = 1.3
		proximityPrompt.Enabled = true
		seat.Parent.Body.Seat.SeatFR.ProximityPrompt.Enabled = true
		seat.Parent.Body.Seat.SeatRL.ProximityPrompt.Enabled = true
		seat.Parent.Body.Seat.SeatRR.ProximityPrompt.Enabled = true
		seat.Parent.Body.Smoke.ParticleEmitter.Enabled = false
	end
end)

proximityPrompt.Triggered:Connect(function(player)
	if player.Character.Humanoid.Sit == false then
		seat:Sit(player.Character.Humanoid)
	end
end)

image

What are you trying to retrieve the player from? The DriveSeat or ProximityPrompt?

The Occupant Property stores the humanoid sitting o nthe seat or nil if no one is sitting on it. You cna make it so when someoe nsits, it gets the Occupant property and changes the height from there and stores the Humanoid in a variable outside of the events, and then when they get off, reference the variable and revert the changes

im kinda confused how i could do that, seat.occupant.humanoid?

i didnt understand what clearly you asked but im trying to make the player height smaller when sitting to fit the car height

Just seat.Occupant is enough to get the Humanoid, something like this should work

local proximityPrompt = script.Parent
local seat = proximityPrompt.Parent

local formerOccupant

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	if seat.Occupant then
		local Humanoid = seat.Ouccpant
		local BHS = Humanoid.BodyHeightScale
		BHS.Value = 1
		proximityPrompt.Enabled = false
		seat.Parent.Body.Seat.SeatFR.ProximityPrompt.Enabled = false
		seat.Parent.Body.Seat.SeatRL.ProximityPrompt.Enabled = false
		seat.Parent.Body.Seat.SeatRR.ProximityPrompt.Enabled = false
		seat.Parent.Body.Smoke.ParticleEmitter.Enabled = true
		formerOccupant = Humanoid
	else
		local BHS = formerOccupant.BodyHeightScale
		BHS.Value = 1.3
		proximityPrompt.Enabled = true
		seat.Parent.Body.Seat.SeatFR.ProximityPrompt.Enabled = true
		seat.Parent.Body.Seat.SeatRL.ProximityPrompt.Enabled = true
		seat.Parent.Body.Seat.SeatRR.ProximityPrompt.Enabled = true
		seat.Parent.Body.Smoke.ParticleEmitter.Enabled = false
		formerOccupant = nil
	end
end)

proximityPrompt.Triggered:Connect(function(player)
	if player.Character.Humanoid.Sit == false then
		seat:Sit(player.Character.Humanoid)
	end
end)

and that worked, thanks for the help!

1 Like

Anytime! If you have anymore issues don’t be afraid to make another post!

And to add, I recommend you make a variable for seat.Parent.Body and then use that variable to put the Seat child as well, something like this

local body = seat.Parent.Body
local bodySeat = body.Seat

And reference that since you’re using seat.Parent.Body.Seat very frequently

So when i sit the player gets smaller but when i get out the player still is small and i cant get in the car anymore, im 100% sure it was me that did something wrong but i cant figure what in the world i did wrong

local proximityPrompt = script.Parent
local seat = proximityPrompt.Parent

local formerOccupant

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	if seat.Occupant then
		local Humanoid = seat.Occupant
		local BHS = Humanoid.BodyHeightScale
		BHS.Value = 0.8
		proximityPrompt.Enabled = false
		seat.Parent.Body.Seat.SeatFR.ProximityPrompt.Enabled = false
		seat.Parent.Body.Seat.SeatRL.ProximityPrompt.Enabled = false
		seat.Parent.Body.Seat.SeatRR.ProximityPrompt.Enabled = false
		seat.Parent.Body.Smoke.ParticleEmitter.Enabled = true
		formerOccupant = Humanoid
	else
		local Humanoid = seat.Occupant
		local BHS = Humanoid.BodyHeightScale
		BHS.Value = 1.3
		proximityPrompt.Enabled = true
		seat.Parent.Body.Seat.SeatFR.ProximityPrompt.Enabled = true
		seat.Parent.Body.Seat.SeatRL.ProximityPrompt.Enabled = true
		seat.Parent.Body.Seat.SeatRR.ProximityPrompt.Enabled = true
		seat.Parent.Body.Smoke.ParticleEmitter.Enabled = false
		formerOccupant = nil
	end
end)

proximityPrompt.Triggered:Connect(function(player)
	if player.Character.Humanoid.Sit == false then
		seat:Sit(player.Character.Humanoid)
	end
end)

since the humanoid is seat.occupant is nil it cant get the humanoid so thats why but idk what to do

Change these lines after the else

local Humanoid = seat.Occupant
local BHS = Humanoid.BodyHeightScale

To

local BHS = formerOccupant.BodyHeightScale

sorry for the late response, but man that worked very well! the character just for less than a second after leaving the car is still small but i think its a “feature”

1 Like

It probably takes a bit of time for the event to kick in, don’t know if there’s a way to get rid of that slight delay