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

Script works in studio testing mode but not in a normal server?

Been using a script to make certain camera angles and one line has an issue. Strangely the issue is only in game, not in test mode by myself, though going into a server makes it have an error in line 14 of this script. Here's the line

game.Players.LocalPlayer.Backpack.cameraScript:FindFirstChild("staticCam").Value = CFrame.new(script.Parent:FindFirstChild("position").CFrame.p,script.Parent:FindFirstChild("focus").CFrame.p)

Here's the entire script

script.Parent:FindFirstChild("zone").Transparency=1
script.Parent:FindFirstChild("position").Transparency=1
script.Parent:FindFirstChild("focus").Transparency=1


function onTouched(part)
	print("touch camera")
	if not game.Players:GetPlayerFromCharacter(part.Parent) then return end
	local p=game.Players:GetPlayerFromCharacter(part.Parent)
	while not p.Backpack:FindFirstChild("cameraScript") do
		print("touchloop")
		wait(2.0)
	end
	print("ended touch loop")
	game.Players.LocalPlayer.Backpack.cameraScript:FindFirstChild("staticCam").Value = CFrame.new(script.Parent:FindFirstChild("position").CFrame.p,script.Parent:FindFirstChild("focus").CFrame.p)

end
 
script.Parent:FindFirstChild("zone").Touched:connect(onTouched)

1 answer

game.Players.LocalPlayer can only be used in a LocalScript. While playing in studio mode, the server is being run on your computer, so game.Players.LocalPlayer would be you. But, in an actual ROBLOX server, game.Players.LocalPlayer could be anyone!

Try using something along the lines of

local player=game.Players.Someone
player.Backpack.cameraScript:FindFirstChild("staticCam").Value = CFrame.new(script.Parent:FindFirstChild("position").CFrame.p,script.Parent:FindFirstChild("focus").CFrame.p)

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