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

Camera wont change when touching trigger?

Asked by 2 years ago

So i was trying to make it so that once you touch the trigger it will set the camera's position to the part's but thing is didnt work and the output printed this:

21:34:03.096 Players.GameBuilderLol.PlayerScripts.LocalScript:9: invalid argument #3 (CFrame expected, got nil) - Client - LocalScript:9

Server Script:

local debounce = false

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        if not debounce then
            debounce = true
            local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
    game.ReplicatedStorage.Events.Changecam:FireClient(plr,script.Parent.Parent.Cam.CFrame)
            wait(1.3)
            debounce = false
        end
    end
end)

Local Script:

game.ReplicatedStorage.Events.Changecam.OnClientEvent:Connect(function(plr, cam)
    local Player = game.Players.LocalPlayer
    local Character = Player.Character or Player.CharacterAdded:Wait()
    local Camera = workspace.CurrentCamera

    repeat wait()
        Camera.CameraType = Enum.CameraType.Scriptable
    until Camera.CameraType == Enum.CameraType.Scriptable
    Camera.CFrame = cam
end)

1 answer

Log in to vote
1
Answered by 2 years ago
Edited 2 years ago

You don't need the extra 'plr' in line 1. In line 1 of the local script, do

game.ReplicatedStorage.Events.Changecam.OnClientEvent:Connect(function(cam)

Since when firing onclientevent, you don't need plr since you can just do game.Players.LocalPlayer. The only time you need the plr is onserverevent

Ad

Answer this question