I’m trying to make it when your LowerTorso is anchored the camera changes but it’s not working how could I fix this?
The script is a LocalScript and it’s located in StarterPlayerScripts.
This is the script.
local DevSnowboardCam = game.Workspace.DevSnowboard
player = game.Players.LocalPlayer
local function CameraChange()
print("CameraMinipulation has started")
local cam = workspace.CurrentCamera
local FocusPart = game.Workspace.DevSnowboard.FocusPoint
local character = player.Character
local LowerTorso = character:FindFirstChild("HumanoidRootPart")
if LowerTorso.Anchored == true then
cam.CameraType = "Fixed"
cam.CFrame = FocusPart.CFrame
end
end
The function for when the LowerTorso gets anchored? If so the script is.
local ProximityPromptService = game:GetService("ProximityPromptService")
local player = game.Players.LocalPlayer
local function onPromptTriggered(promptObject, player)
if promptObject.Name == "DevSnowboard" then
print(player.Name.. " mounted Dev board")
local character = player.Character
if character then -- double check that the character exists
local LowerTorso = character:FindFirstChild("HumanoidRootPart")
character.HumanoidRootPart.Position = script.Parent.Parent.Parent.MountBoard.Position
wait(.5)
local character = player.Character
if character then -- double check that the character exists
local LowerTorso = character:FindFirstChild("HumanoidRootPart")
if LowerTorso then -- ensure torso is loaded in
LowerTorso.Anchored = true
end
end
end
end
end
ProximityPromptService.PromptTriggered:Connect(onPromptTriggered)
I’m talking about the camera Change function.
edit: Why can’t you just call the camera change function in the proximity prompt like this:
if character then -- double check that the character exists
local LowerTorso = character:FindFirstChild("HumanoidRootPart")
if LowerTorso then -- ensure torso is loaded in
LowerTorso.Anchored = true
CameraChange()
end
end
Their block of code wasn’t enclosed in a function that’s why it ran. Since it’s a function you have to execute using
local function CameraChange()
-- whatever here
end
CameraChange() -- that's it it'll run the function
I recommend reading up on functions in case you need a refresher or are new to functions.
Quick Overview
function printSomething()
print "Printed from a function!" -- this won't print until you call the function!
end
print "I printed outside the function!" -- this will print when the script runs ONCE
print "I also printed outside!" -- notice we have to write everything over again
printSomething() -- now we print the function print
printSomething()
printSomething()
printSomething() -- and we can repeat it as many times as we like!
You literally took that out of my breath, I had noticed he didn’t call the function, So the function wouldn’t work!, You need to Call CameraChange for the Function to run, that could be why your camera isn’t changing!
At first I was getting no errors and no output. But now im experiencing a new error (Which means the function ran). But how could I fix this.
I’m getting the error
Players.MilitaryWarFire.PlayerScripts.CameraManipulation:11: attempt to index nil with ‘FindFirstChild’
This is the script now.
local DevSnowboardCam = game.Workspace.DevSnowboard
player = game.Players.LocalPlayer
local function CameraChange()
print("CameraMinipulation has started")
local cam = workspace.CurrentCamera
local FocusPart = game.Workspace.DevSnowboard.FocusPoint
local character = player.Character
local LowerTorso = character:FindFirstChild("HumanoidRootPart")
if LowerTorso.Anchored == true then
cam.CameraType = "Fixed"
cam.CFrame = FocusPart.CFrame
end
end
CameraChange()
Okay so this is because character isn’t loading in fast enough…
Use:
local character = player.Character or player.CharacterAdded:Wait() -- wait until character added if not added yet
local LowerTorso = character:WaitForChild("HumanoidRootPart") -- wait for humanoidRootTorso to load in
Instances don’t load in right away so it’s important to use waits where possible (sometimes you shouldn’t wait because it could wait FOREVER so it’s case by case)
I thought this would happen. So now we know about calling functions. But now we need to call it when we need it! So instead of just calling it, we can connect it to an event. The event being when the Torso gets anchored. (also, if you want the lowertorso anchored then we won’t be using “HumanoidRootPart”)
First Change This
local lowerTorso = character:WaitForChild("LowerTorso")
:GetPropertyChangedSignal(someString) : Instances have attributes (like parts have Size, Position, and so on. So whatever string we put where someString is, we can fire the connected function everytime that Property changes. Source
Connect : is how you connect the event to something. Source
And lastly, we place our function as the parameter for Connect as that’s the function we want to run everytime the Anchored property changes for LowerTorso.
--variables
local DevSnowboardCam = game.Workspace.DevSnowboard
player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait() -- wait until character added if not added yet
local LowerTorso = character:WaitForChild("LowerTorso") -- wait for humanoidRootTorso to load in
local function CameraChange()
--Variables Inside Function
local cam = workspace.CurrentCamera
local FocusPart = game.Workspace.DevSnowboard.FocusPoint
--Camera Change
print("CameraMinipulation has started")
cam.CameraType = "Fixed"
cam.Focus = FocusPart.CFrame
end
LowerTorso:GetPropertyChangedSignal("Anchored"):Connect(CameraChange)