Is there any way I can change the orientation of a model without it saying that something isn’t a valid member of whatever I’m trying to move?
local userInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local SpotlightHead = game.Workspace.Spotlight.Head
local UpdateCon
userInputService.InputBegan:Connect(function(input, gameProcessedEvent)
if input.UserInputType ~= Enum.UserInputType.Keyboard then return end
if input.KeyCode ~= Enum.KeyCode.Q then return end
if UpdateCon then
UpdateCon:Disconnect()
UpdateCon = nil
end
UpdateCon = RunService.Heartbeat:Connect(function(dt)
SpotlightHead.Orientation = Vector3.new(0, 0.1, 0)
end)
end)
userInputService.InputEnded:Connect(function(input, gameProcessedEvent)
if input.UserInputType ~= Enum.UserInputType.Keyboard then return end
if input.KeyCode ~= Enum.KeyCode.Q then return end
if not UpdateCon then return end
UpdateCon:Disconnect()
UpdateCon = nil
end)
It is specifically telling me that, Orientation is not a valid member of Model “Workspace.Spotlight.Head”
Change this line to:
SpotlightHead:PivotTo(CFrame.new(Vector3.new(0, 0.1, 0)))
1 Like
I already figured this out a bit ago, by changing the line to:
local newCFrame = SpotlightHead.PrimaryPart.CFrame * CFrame.Angles(0.1, 0, 0)
SpotlightHead:SetPrimaryPartCFrame(newCFrame)
But this also worked so I’ll consider this a good solution
Also, just another question that came to mind:
Is there any way to make this code only work if you are sitting on a seat?
Like, when you sit on a seat part, the code activates or something like that.
You should still use PivotTo, as SetPrimaryPartCFrame has some nasty offset issues, and PivotTo fixes that bug.
Edit:
Do you mean this code activates when you sit down or the code only triggers while you’re sitting down?
I’ll say it this way.
The code works when I use the W key, which means it happens when I walk.
So, I want it to only work when I am sitting on a seat part, where I am not moving.
You can probably check if the player’s character’s humanoid’s Sit
is true. If it’s true, that means that the player is sitting on something.
Where can I implement that into my code? (you can look at the code I showed previously)
[EDIT] By the way, is there a way to make it for a SPECIFIC seat?
You can probably implement it at the start of the InputBegan
event. Also, if you want the model to stop moving when the player gets out of the seat, you can also use the Seated
event to disconnect it like with InputEnded
, although that would be outside the other events.
So would something like “humanoid.Seated:Connect(onSeated)” work?
As long as OnSeated
checked that the character wasn’t seated at the time.
I have this code:
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
function onSeated(isSeated, seat)
if isSeated then
humanoid.Seated:Connect(onSeated)
This code is in StarterCharacterScripts. (something will come after “if isSeated then”)
Problem is, the 4 LocalScripts that control the spotlight are in a different area, so is there a way that I can make it so that this script can activate those when the player is seated?