Change orientation

Creating a script where once the player sits, the orientation of one of the parts will change. Then, when the player gets up, the orientation of the part will change back. I cannot get the orientation part to work. Can anybody help?

Script:

local seat = script.Parent
local prompt = seat.Attachment.ProximityPrompt
local chair1 = script.Parent.Chair1
local plrs = game:GetService("Players")
local currentPlayer = nil

prompt.Triggered:Connect(function(plr)
	local char = plr.Character
	seat:Sit(char.Humanoid)
	prompt.Enabled = false
	print('prompt disabled')
	chair1.Orientation += Vector3.new(90,0,0)
	print('orientation changed')
	end)


seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	local player = seat.Occupant
	if player then
		local player = plrs:GetPlayerFromCharacter(hum.Parent)
		prompt.Enabled = false
		print('prompt disabled')
		currentPlayer = player
		print('former player is', currentPlayer)
		chair1.Orientation += Vector3.new(90,0,0)
		print('orientation changed')
	else
		prompt.Enabled = true
		print('prompt enabled')
		currentPlayer = nil
		print('former player is nil')
		chair1.Orientation -= Vector3.new(90,0,0)
		print('orientation changed')
	end
end)

There are lots of errors in the script, here’s the rewritten one:

local seat = script.Parent
local prompt = seat.Attachment.ProximityPrompt
local chair1 = script.Parent.Chair1
local plrs = game:GetService("Players")
local currentPlayer = nil

local orientation = chair1.Orientation
local originalOrientation = orientation -- saves the orientation of chair1
local newOrientation = orientation + Vector3.new(90,0,0)

prompt.Triggered:Connect(function(plr)
	local char = plr.Character
	seat:Sit(char.Humanoid)
	prompt.Enabled = false
	print('prompt disabled')
	chair1.Orientation = newOrientation
	print('orientation changed')
end)


seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	local hum = seat.Occupant
	if hum then
		local player = plrs:GetPlayerFromCharacter(hum.Parent)
		prompt.Enabled = false
		print('prompt disabled')
		currentPlayer = player
		print('former player is', currentPlayer)
		chair1.Orientation = newOrientation
		print('orientation changed')
	else
		prompt.Enabled = true
		print('prompt enabled')
		currentPlayer = nil
		print('former player is nil')
		chair1.Orientation = originalOrientation
		print('orientation changed')
	end
end)
1 Like

Thank you! This works. I see where I went wrong now. Thanks for the help!

1 Like

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