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

Camera wont change when touching trigger?

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

✓ Accepted answer

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

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