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 3 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:

01local debounce = false
02 
03script.Parent.Touched:Connect(function(hit)
04    if hit.Parent:FindFirstChild("Humanoid") then
05        if not debounce then
06            debounce = true
07            local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
08    game.ReplicatedStorage.Events.Changecam:FireClient(plr,script.Parent.Parent.Cam.CFrame)
09            wait(1.3)
10            debounce = false
11        end
12    end
13end)

Local Script:

01game.ReplicatedStorage.Events.Changecam.OnClientEvent:Connect(function(plr, cam)
02    local Player = game.Players.LocalPlayer
03    local Character = Player.Character or Player.CharacterAdded:Wait()
04    local Camera = workspace.CurrentCamera
05 
06    repeat wait()
07        Camera.CameraType = Enum.CameraType.Scriptable
08    until Camera.CameraType == Enum.CameraType.Scriptable
09    Camera.CFrame = cam
10end)

1 answer

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

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

1game.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