I would like some help to fix the issue shown in the video of the camera function working while testing, but not functioning in game.

I’ve tried searching online such as the dev forums, but I can’t find anything so far.

Sooooo… can we see the code, or should we just guess what the problem is?

My bad I’m kinda new to this

local script:

local tool = script.Parent
local equipped = false
local hologram = game.ReplicatedStorage.Stored.Hologram
local maxDist = 25
local rotateKeybind = Enum.KeyCode.R
local UIS = game:GetService("UserInputService")
local cameraInfoRE = game.ReplicatedStorage.RemoteEvents.CameraInfo
local removeCamRE = game.ReplicatedStorage.RemoteEvents.RemoveCamera
local placed = false

local rotateConnection

tool.Equipped:Connect(function(mouse)
	hologramClone = hologram:Clone()
	hologramClone.Parent = workspace
	mouse.TargetFilter = hologramClone
	equipped = true

	rotateConnection = 	UIS.InputBegan:Connect(function(pressed)
		if pressed.KeyCode == rotateKeybind or pressed.KeyCode == Enum.KeyCode.ButtonB then
			hologramClone:PivotTo(hologramClone.PrimaryPart.CFrame * CFrame.Angles(0, math.rad(90), 0))

		end
	end)
	
	if UIS.TouchEnabled then
		local mobileUI = game.Players.LocalPlayer.PlayerGui.MobileUI
		local rotateButton = mobileUI.RotateButton
		mobileUI.Enabled = true
		
		rotateButton.MouseButton1Down:Connect(function()
			hologramClone:PivotTo(hologramClone.PrimaryPart.CFrame * CFrame.Angles(0, math.rad(90), 0))
		end)
		
	end

	mouse.Button1Down:Connect(function()
		if placed == false then

			placed = true
			cameraInfoRE:FireServer(hologramClone.PrimaryPart.CFrame)

			wait(0.05)

			for i, v in pairs(workspace:GetChildren()) do
				local attributeCheck = v:GetAttribute("Name")

				if attributeCheck == game.Players.LocalPlayer.Name then
					local screen = v:WaitForChild("Screen")
					
					workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
					workspace.CurrentCamera.FieldOfView = 80
					workspace.CurrentCamera.CFrame = screen.CFrame * CFrame.Angles(0,math.rad(-90),0)
				end
			end

		else
			placed = false
			removeCamRE:FireServer()

			wait (0.05)

			workspace.CurrentCamera.FieldOfView = 70
			workspace.CurrentCamera.CameraType = Enum.CameraType.Custom

		end
	end)

	while equipped == true do
		task.wait(0.01)

		if game.Players.LocalPlayer.Character.Humanoid.Health == 0 then
			removeCamRE:FireServer()
			hologramClone:Destroy()
			workspace.CurrentCamera.FieldOfView = 70
			workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
		end

		if placed == true then

			for i, v in pairs(hologramClone:GetChildren()) do
				v.Transparency = 1
				hologramClone:FindFirstChild("Bottom").Decal.Transparency = 1
			end

		else

			for i, v in pairs(hologramClone:GetChildren()) do
				v.Transparency = 0.5
				hologramClone:FindFirstChild("Bottom").Decal.Transparency = 0.5
			end
		end

		local mouseCFrame = mouse.Hit:ToWorldSpace()
		local HRPPos = game.Players.LocalPlayer.Character:FindFirstChild("HumanoidRootPart").CFrame.Position
		local dist = (HRPPos - mouseCFrame.Position).Magnitude
		if dist < maxDist then
			hologramClone:MoveTo(mouseCFrame.Position)
		end
	end
end)

tool.Unequipped:Connect(function()

	if rotateConnection then
		rotateConnection:Disconnect()
		rotateConnection = nil
	end
	
	if UIS.TouchEnabled then
		local mobileUI = game.Players.LocalPlayer.PlayerGui.MobileUI
		mobileUI.Enabled = false
	end
		
	equipped = false
	hologramClone:Destroy()
end)

Server script:

local cameraInfoRE = game.ReplicatedStorage.RemoteEvents.CameraInfo
local removeCamRE = game.ReplicatedStorage.RemoteEvents.RemoveCamera
local fakeCam = game.ReplicatedStorage.Stored.FakeCamera

cameraInfoRE.OnServerEvent:Connect(function(plr, cameraInfo)
	local handle = plr.Character:FindFirstChild("Portable Camera"):FindFirstChild("Handle")
	local plrName = plr.Name
	local clone = fakeCam:Clone()
	clone:SetAttribute("Name", plr.Name)
	clone.PrimaryPart.CFrame = cameraInfo * CFrame.Angles(0,math.rad(90),0)
	clone.Parent = workspace
	handle.Transparency = 1
	
	for i, v in pairs(handle:GetChildren()) do
		if v:IsA("Part") then
			v.Transparency = 1
		end
	end
	
end)

removeCamRE.OnServerEvent:Connect(function(player)
	local cam = player.Character:FindFirstChild("Portable Camera")
	cam:FindFirstChild("Handle").Transparency = 0
	for i, v in pairs(workspace:GetChildren()) do
		local attributeCheck = v:GetAttribute("Name")
		if attributeCheck == player.Name then
			v:Destroy()
		end
	end
	
	for i, v in pairs(cam:FindFirstChild("Handle"):GetChildren()) do
		if v:IsA("Part") then
			v.Transparency = 0
		end
	end
	
end)
1 Like

I’d heavily suggest changing your camera spawning code to use a RemoteFunction instead, so that it will properly yield until the camera has spawned.
Just to make sure, can you print when the code reaches local screen = v:WaitForChild("Screen"), and then show what comes up in console when you place the camera down (F9)? In the actual game, of course.

Also, I refactored your code a little, but you don’t have to use it:

local cameraInfoRE = game.ReplicatedStorage.RemoteEvents.CameraInfo
local removeCamRE = game.ReplicatedStorage.RemoteEvents.RemoveCamera
local fakeCam = game.ReplicatedStorage.Stored.FakeCamera

cameraInfoRE.OnServerEvent:Connect(function(plr, cameraInfo)
	local handle = plr.Character:FindFirstChild("Portable Camera"):FindFirstChild("Handle")
	local plrName = plr.Name
	local clone = fakeCam:Clone()
	clone:SetAttribute("Name", plr.Name)
	clone.PrimaryPart.CFrame = cameraInfo * CFrame.Angles(0,math.rad(90),0)
	clone.Parent = workspace
	handle.Transparency = 1
	
	for _, child in pairs(handle:GetChildren()) do
		if child:IsA("Part") then child.Transparency = 1 end
	end
	
end)

removeCamRE.OnServerEvent:Connect(function(player)
	local cam = player.Character:FindFirstChild("Portable Camera")
	cam:FindFirstChild("Handle").Transparency = 0
	for _, child in pairs(workspace:GetChildren()) do
		local attributeCheck = child:GetAttribute("Name")
		if attributeCheck == player.Name then child:Destroy() end
	end
	
	for _, child in pairs(cam:FindFirstChild("Handle"):GetChildren()) do
		if child:IsA("Part") then child.Transparency = 0 end
	end
end)

I should mention that you aren’t forced to write for i,v in. You can write anything, like for apples, bananas in, or for _, inst in.
Also, if myVariable == true then is the same as if myVariable then, and if myVariable == false then is the same as if not myVariable then.

1 Like

Thanks! Your solution to changing remote events to remote functions worked.

1 Like