Hi devs, i need help with one of my script. Actually i have maid a script that change the player camera to a part and after that i want to give back the camera to the basic player vision; But it doesn’t work. So if someone can help me with that.
local script :
local cam = workspace.CurrentCamera
local runService = game:GetService("RunService")
local part = workspace.Cameras.StartPartCamera
local camera1 = workspace.Cameras.Camera1
runService.RenderStepped:Connect(function()
cam.CFrame = part.CFrame
end)
-- Script
local transitionTime = 3
local startPosition = cam.CFrame
local endPosition = camera1.CFrame
local tweenInfo = TweenInfo.new(transitionTime)
local tween = TweenService:Create(cam, tweenInfo, {CFrame = endPosition})
tween:Play()
tween.Completed:Connect(function()
cam.CameraSubject = camera1
part = camera1
wait(28)
print("camera back")
cam.CameraSubject = LocalPlayer.Character.Humanoid -- not working
end)
end)
Additionally, you also want to look for the HRP incase there’s a player with horrible internet:
if LocalPlayer.Character and LocalPlayer.Character:FindFirstChild("HumanoidRootPart") then
cam.CFrame = LocalPlayer.Character.HumanoidRootPart
else
repeat wait() until LocalPlayer.Character:FindFirstChild("HumanoidRootPart")
cam.CFrame = LocalPlayer.Character.HumanoidRootPart
end
09:46:12.369 Unable to assign property CFrame. CoordinateFrame expected, got Instance - Client - Intro:189
09:46:12.369 Stack Begin - Studio
09:46:12.369 Script ‘Players.Tacca_BioX.PlayerGui.IntroGui.Intro’, Line 189 - Studio - Intro:189
09:46:12.369 Stack End - Studio
if LocalPlayer.Character and LocalPlayer.Character:FindFirstChild("HumanoidRootPart") then
cam.CFrame = LocalPlayer.Character.HumanoidRootPart
else
repeat wait() until LocalPlayer.Character:FindFirstChild("HumanoidRootPart")
cam.CFrame = LocalPlayer.Character.HumanoidRootPart
end
local cam = workspace.CurrentCamera
local runService = game:GetService("RunService")
local part = workspace.Cameras.StartPartCamera
local camera1 = workspace.Cameras.Camera1
runService.RenderStepped:Connect(function()
cam.CFrame = part.CFrame
end)
-- script
local transitionTime = 3
local startPosition = cam.CFrame
local endPosition = camera1.CFrame
local tweenInfo = TweenInfo.new(transitionTime)
local tween = TweenService:Create(cam, tweenInfo, {CFrame = endPosition})
tween:Play()
tween.Completed:Connect(function()
cam.CameraSubject = camera1
part = camera1
wait(28)
print("camera back")
if LocalPlayer.Character and LocalPlayer.Character:FindFirstChild("HumanoidRootPart") then
cam.CFrame = LocalPlayer.Character.HumanoidRootPart
else
repeat wait() until LocalPlayer.Character:FindFirstChild("HumanoidRootPart")
cam.CFrame = LocalPlayer.Character.HumanoidRootPart
end
end)
end)
here is the error :
09:57:04.560 Unable to assign property CFrame. CoordinateFrame expected, got Instance - Client - Intro:189
09:57:04.560 Stack Begin - Studio
09:57:04.560 Script ‘Players.Tacca_BioX.PlayerGui.IntroGui.Intro’, Line 189 - Studio - Intro:189
09:57:04.560 Stack End - Studio
wait(28)
print("camera back")
if LocalPlayer.Character and LocalPlayer.Character:FindFirstChild("HumanoidRootPart") then
cam.CFrame = LocalPlayer.Character.HumanoidRootPart.CFrame
else
repeat wait() until LocalPlayer.Character:FindFirstChild("HumanoidRootPart")
cam.CFrame = LocalPlayer.Character.HumanoidRootPart.CFrame
end
end)
Make sure you :Disconnect() this when trying to reapply Camera to the Character, this will be firing every single frame, and therefore will be applied every frame, so make sure you are keeping track of when this is firing.
You also don’t need to apply the CamerasCFrame back to the PlayersCharacter like this, it will be applied automatically when the CameraType is set back to Custom, and if the CameraSubject remains as their Humanoid.
By Keeping track of the Connection using a Variable, you can predefine the variable before hand so it can be accessed anywhere in the script, for example:
local RenderStepped
-- predefined before anything else
-- if done correctly, we can use it throughout our entire
-- script!
-- To Keep track of this connection, we can tell our Variable
-- to hold our Connect that we will be using, like so:
RenderStepped = runService.RenderStepped:Connect(function()
-- some code goes here
end)
-- our Variable is Assigned our RenderStepped Connection, now we can keep
-- track of it, and modify it when nessacary.
-- When the Connection is no longer needed, all you need to do is call the
-- :Disconnect() function, and remove the Connection from the Variable, for
-- Example:
RenderStepped:Disconnect() -- Stops the Connection from Running
RenderStepped = nil -- Removes the Connection
-- You Cannot Reconnect the same Connection, you need to create
-- a new one to do that.
-- However before trying to Disconnect, make sure you have a Connection in the
-- First place, otherwise you'll get an error
if RenderStepped then
-- Disconnect here
end