Hey so i have this scirpt that morphs the player into another character after 3 seconds but the thing is for some reason theres this camera glitch that makes the camera not follow the player like on the video i hope someone can help me!
local Players = game:GetService("Players")
local box = workspace
local characterName = "Char"
Players.PlayerAdded:Connect(function(player)
local hasMorphed = false
player.CharacterAdded:Connect(function(character)
if hasMorphed then return end
hasMorphed = true
task.delay(1, function()
local customChar = box:FindFirstChild(characterName)
if customChar then
local charClone = customChar:Clone()
charClone.Name = player.Name
local spawnCFrame = character:FindFirstChild("HumanoidRootPart") and character.HumanoidRootPart.CFrame
charClone.Parent = workspace
player.Character = charClone
local rootPart = charClone:FindFirstChild("HumanoidRootPart") or charClone:FindFirstChild("Torso")
if rootPart and spawnCFrame then
rootPart.CFrame = spawnCFrame
end
local humanoid = charClone:FindFirstChildOfClass("Humanoid")
if humanoid then
workspace.CurrentCamera.CameraSubject = humanoid
end
end
end)
end)
end)
The video
Try adding a print()
function in this if statement to check if it actually runs or not.
Also, are there any errors in the output?
1 Like
Yes this stament does run and no there is no errors in the output
maybe you could try set the Camera.CameraType
to an Enum like Enum.CameraType.Track
. I’m not exactly sure what the issue is
1 Like
It’s because Workspace.CurrentCamera
can only be used in the client. You need to set CurrentCamera
in a local script (either inside StarterGui
or StarterPlayer.StarterPlayerScripts
). You need to use a RemoteEvent
in ReplicatedStorage
for this.
Server Script in ServerScriptService
:
local Players = game:GetService("Players")
local box = workspace
local characterName = "Char"
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage.YOUR_REMOTE_EVENT_NAME
Players.PlayerAdded:Connect(function(player)
local hasMorphed = false
player.CharacterAdded:Connect(function(character)
if hasMorphed then return end
hasMorphed = true
task.delay(1, function()
local customChar = box:FindFirstChild(characterName)
if customChar then
local charClone = customChar:Clone()
charClone.Name = player.Name
local spawnCFrame = character:FindFirstChild("HumanoidRootPart") and character.HumanoidRootPart.CFrame
charClone.Parent = workspace
player.Character = charClone
local rootPart = charClone:FindFirstChild("HumanoidRootPart") or charClone:FindFirstChild("Torso")
if rootPart and spawnCFrame then
rootPart.CFrame = spawnCFrame
end
local humanoid = charClone:FindFirstChildOfClass("Humanoid")
if humanoid then
RemoteEvent:FireClient(player, humanoid)
end
end
end)
end)
end)
Local Script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("YOUR_REMOTE_EVENT_NAME")
RemoteEvent.OnClientEvent:Connect(function(humanoid)
workspace.CurrentCamera.CameraSubject = humanoid
end)