Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Problems with camera manipulation?

Asked by
sheepposu 561 Moderation Voter
4 years ago

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
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 Gameplayer365247v2 1055 — 4y
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 sheepposu 561 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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! :)

0
Thx for noticing my mistake there, but I don't believe this will fix the problem with the camera sheepposu 561 — 4y
0
instead of putting Camera.CFrame, it needs to be Camera.CoordinateFrame in the local script! InfinityEngine 223 — 4y
Ad

Answer this question