Local Script Working In Studio, But Not In-Game

I want this script to work in-game, so I can get the perspective a player would receive. It works in Studio, but not when I publish it. Any help would be appreciated.

script.Parent.MouseButton1Click:Connect(function()
	wait(14)
	
	
	for i, player in pairs(AliveTeam:GetPlayers()) do
		if player then
			table.insert(tps,player)
		end
	end
	for i, player in pairs(tps) do
		if player then
			character = player.Character

			if character then
				character:FindFirstChild("HumanoidRootPart").CFrame = LaunchroomSpots[1].CFrame * CFrame.new(0, 0, -1)
				table.remove(LaunchroomSpots,1)
			end
		end
	end
end)

This game is under a group if that helps at all.

is there any error in the output?

There is an error for this script:

script.Parent.MouseButton1Click:Connect(function()
	wait(3)
	IntroCam()
	wait(5.5)
	cc.CameraType = Enum.CameraType.Custom
	local tplayer = player.Name
	local human = workspace:FindFirstChild("tplayer")
	cam.CFrame = human.Head
end)

It works completely fine in studio though.

have you committed the script in drafts?

1 Like

I am not sure what you are talking about. Would you mind explaining?

If collaborative editing is enabled in game settings, then you will need to commit a draft of the script for it to work outside of studio. If so you’ll find the drafts in the view tab, then you just need to click on your script and press commit
image

1 Like

Try using :WaitForChild(“Head”)

The issue stays the same when I attempt that.

Is ‘cam’ defined? I don’t see it being defined anywhere, and the error says that it’s nil—or at least that’s what I believe it says.

Yeah. My script works 100% the way I want it to in studio.

If that is so, would you be able to give us the full script, including the part in it where you define the ‘cam’?

This is the full script:

local event = game:GetService("ReplicatedStorage"):WaitForChild("ToPadRoomFade")

script.Parent.MouseButton1Click:Connect(function()
	event:FireServer()
end)

local TweenService = game:GetService("TweenService")
local cam = game.Workspace.CurrentCamera
local player = game.Players.LocalPlayer
local cameratype = Enum.CameraType.Scriptable
local cameratypechanged = cam:GetPropertyChangedSignal("CameraType")
local pcamera = game.Workspace.PadRoomFromCamera
local campos = cam.CFrame.Position
local partpos = game.Workspace.exggs.Position
local cc = workspace.CurrentCamera

local tween1Rise = TweenService:Create(
	cam,
	TweenInfo.new(45, Enum.EasingStyle.Linear, Enum.EasingDirection.Out),
	{
		CFrame = CFrame.new(partpos) * CFrame.Angles(0,math.rad(-90),0)
	}
)
local function IntroCam()
	cam.CameraType = Enum.CameraType.Scriptable
	cam.CFrame = pcamera.CFrame
	wait(2)
	tween1Rise:Play()
	wait(14.5)
	tween1Rise:Pause()
end

script.Parent.MouseButton1Click:Connect(function()
	wait(3)
	IntroCam()
	wait(5.5)
	cc.CameraType = Enum.CameraType.Custom
	local tplayer = player.Name
	local human = workspace:FindFirstChild("tplayer")
	cam.CFrame = human:WaitForChild("Head")
end)



local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera
local press = script.Parent
local looking = false
local endCFrame = CFrame.new(-189.72, -465.1, 1167.355)
local tweentime = 12
local active = false

local LaunchroomSpots = game.Workspace.fromlaunch:GetChildren()
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
local AliveTeam = Teams.Alive
local tps = {}
local ReplicatedStorage = game:GetService("ReplicatedStorage")



script.Parent.MouseButton1Click:Connect(function()
	wait(14)
	
	
	for i, player in pairs(AliveTeam:GetPlayers()) do
		if player then
			table.insert(tps,player)
		end
	end
	for i, player in pairs(tps) do
		if player then
			character = player.Character

			if character then
				character:FindFirstChild("HumanoidRootPart").CFrame = LaunchroomSpots[1].CFrame * CFrame.new(0, 0, -1)
				table.remove(LaunchroomSpots,1)
			end
		end
	end
end)

Add a wait at the start of the script

Also why do you have cc when you have cam?