Player script not working

Hey! So I was making a script for my game, so that when the first player joins, they will be assigned a cannon that they can control and a camera. When the second player joins, they SHOULD be assigned to a separate cannon and camera, but for some reason they don’t get assigned to anything. Here’s the code if you need it (sorry if its messy, i was messing around with it a lot)

            if firstPlayer == game.Players.LocalPlayer and not workspace.BlueCamera.IsTaken.Value then
--Player 1--
print("Setting up "..player1.Value.Name.."'s client")
workspace.BlueCamera.Taken:FireServer()
camera.CFrame = workspace.BlueCamera.CFrame
--PC--
UIS.InputBegan:Connect(function(input, processed)
	if input.KeyCode == Enum.KeyCode.Q and not processed then
		blueCannon.Movement.Move:FireServer("Left", true)
		UIS.InputEnded:Connect(function(input)
			if input.KeyCode == Enum.KeyCode.Q then
				blueCannon.Movement.Move:FireServer("Left", false)
			end
		end)
	elseif input.KeyCode == Enum.KeyCode.E and not processed then
		blueCannon.Movement.Move:FireServer("Right", true)
		UIS.InputEnded:Connect(function(input)
			if input.KeyCode == Enum.KeyCode.E then
				blueCannon.Movement.Move:FireServer("Right", false)
			end
		end)
	end
end)
--Mobile--
if UIS.TouchEnabled then
	mobileControls.Enabled = true
	mobileControls.Left.MouseButton1Down:Connect(function()
		blueCannon.Movement.Move:FireServer("Left", true)
		mobileControls.Left.MouseLeave:Connect(function()
			blueCannon.Movement.Move:FireServer("Left", false)
		end)
	end)
	mobileControls.Right.MouseButton1Down:Connect(function()
		blueCannon.Movement.Move:FireServer("Right", true)
		mobileControls.Right.MouseLeave:Connect(function()
			blueCannon.Movement.Move:FireServer("Right", false)
		end)
	end)
end
 else
--Player 2--
print("Setting up "..player2.Value.Name.."'s client")
workspace.RedCamera.Taken:FireServer()
camera.CFrame = workspace.RedCamera.CFrame
--PC--
UIS.InputBegan:Connect(function(input, processed)
	if input.KeyCode == Enum.KeyCode.Q and not processed then
		redCannon.Movement.Move:FireServer("Left", true)
		UIS.InputEnded:Connect(function(input)
			if input.KeyCode == Enum.KeyCode.Q then
				redCannon.Movement.Move:FireServer("Left", false)
			end
		end)
	elseif input.KeyCode == Enum.KeyCode.E and not processed then
		redCannon.Movement.Move:FireServer("Right", true)
		UIS.InputEnded:Connect(function(input)
			if input.KeyCode == Enum.KeyCode.E then
				redCannon.Movement.Move:FireServer("Right", false)
			end
		end)
	end
end)
--Mobile--
if UIS.TouchEnabled then
	mobileControls.Enabled = true
	mobileControls.Left.MouseButton1Down:Connect(function()
		redCannon.Movement.Move:FireServer("Left", true)
		mobileControls.Left.MouseLeave:Connect(function()
			redCannon.Movement.Move:FireServer("Left", false)
		end)
	end)
	mobileControls.Right.MouseButton1Down:Connect(function()
		redCannon.Movement.Move:FireServer("Right", true)
		mobileControls.Right.MouseLeave:Connect(function()
			redCannon.Movement.Move:FireServer("Right", false)
		end)
	end)
end
end

I believe you must do camera.CameraType = Enum.CameraType.Scriptable before switching the camera. https://developer.roblox.com/en-us/api-reference/property/Camera/CameraType

Yea, I already did that. Even if that was the problem, it wouldn’t solve the fact that the controls weren’t being assigned to the second player.

You shouldn’t need the two control systems in the same script, each person will be assigned their own script when they join, i.e. they will both be local players to their clients. All you have to do is check which cannon to assign them by checking which ones are free.

1 Like