Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Problems with camera manipulation?

Whenever I start the game it does everything correctly except anchor the player's character on the cam part. It goes right through the code for anchoring the player's character so no errors, it just doesn't work like it should. My first thought was, maybe the camera isn't loaded in or something so I had it wait till the camera loaded in but that didn't work. So I'm here. Thx in advance for any help. server script in ServerScriptService

game.Players.PlayerAdded:Connect(function(plr)
	for _, Spawn in pairs(workspace.Spawns:GetChildren()) do
		if Spawn.Available.Value then
			Spawn.Available.Value = false
			game.ReplicatedStorage.Events.Spawn:FireClient(plr, Spawn)
			break
		end
	end
end)

game.ReplicatedStorage.Events.Spawn.OnServerEvent:Connect(function(plr, Spawn)
	game.ReplicatedStorage.Events.Spawn:FireClient(plr, Spawn)
end)

My LocalScript in StarterPlayerScripts (look to line 6)

local Sp

game.ReplicatedStorage.Events.Spawn.OnClientEvent:Connect(function(Spawn)
	local cam = workspace.CurrentCamera
	cam.CameraType = Enum.CameraType.Scriptable
	cam.CFrame = Spawn.Cam.CFrame
	local S = Spawn.Spawn
	Sp = Spawn
	repeat wait() until game.Players.LocalPlayer.Character
	repeat wait() until game.Players.LocalPlayer.Character:FindFirstChild('Humanoid')
	game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 0
	game.Players.LocalPlayer.Character.Humanoid.JumpPower = 0
	game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(S.Position.X, S.Position.Y + 15, S.Position.Z))
end)

while true do
	repeat wait() until game.Players.LocalPlayer.Character
	if game.Players.LocalPlayer.Character:WaitForChild('Humanoid').Health <= 0 and game.Players.LocalPlayer.PlayerGui.StartScreen.Enabled then
		wait(5)
		game.ReplicatedStorage.Events.Spawn:FireServer(Sp)
	end
end

2 comments

0

i cant fully answer this right now because im really tired but what i can tell fast is that setting the cameras cframe to another object sets it to the way the object is facing, you can check that in part properties

0

Yes, I know that. The part is set to face the direction I need it to. The problem is that the camera CFrame doesn't actually go onto the part. It runs straight through that line and does everything else

1 answer

You can't teleport a player using a local script, it can only be done through the server. This is because teleporting a player through the client only allows the single Player to see it, not the other players. This can be fixed by simply using a remote function to fire an event that teleports a player to a certain position.

Example:

In server (Script):

local RemoteEvent = game.ReplicatedStorage.TeleportPlayer

RemoteEvent.OnServerEvent:connect(function(plr)
	local Char = plr.Character
	Char.HumanoidRootPart.CFrame = CFrame.new() -- Whatever the CFrame of the torso needs to be
end)

In client (LocalScript):

local RemoteEvent = game.ReplicatedStorage.TeleportPlayer

RemoteEvent:FireServer()

I hope this is of some use to you! If not, let me know how else I can help! :)

2 comments

0

Thx for noticing my mistake there, but I don't believe this will fix the problem with the camera

0

instead of putting Camera.CFrame, it needs to be Camera.CoordinateFrame in the local script!

This discussion is preserved as it was. New answers, comments, and votes are closed.