Script works in studio, not in live game?

print("f")
local players = game:GetService("Players")
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local regiments = {
	{TAG = "PATROL", ID = 5786049},
	{TAG = "RGR", ID = 5310724},
	{TAG = "UKSF", ID = 5029915},
	{TAG = "RMP", ID = 4972920},
	{TAG = "RGG", ID = 4973182},
	{TAG = "ETS", ID = 5237367},
	{TAG = "BOP", ID = 4994558},
	{TAG = "PARAS", ID = 4973512},
	{TAG = "AAC", ID = 5310715},
	{TAG = "RAMC", ID = 5310746},
	{TAG = "JA", ID = 5310728},
	{TAG = "RIC", ID = 5216554},
	{TAG = "CRE", ID = 5310751}
}

local function isin(player,id)
	if player:IsInGroup(id) then
		print("you are in"..id)
		return true
	end
end
print("check1")
local function get_regiments(player)
	local player_regiments = {}
	for i = 1,#regiments do
		local rg = regiments[i]
		if isin(player,rg.ID) then
			table.insert(player_regiments,rg)
			print(rg)	
		end
	end
	return player_regiments
end
print("check2")


		local playerhead = char:WaitForChild("Head",math.huge)
		local localcolor = player.TeamColor.Color
		local plrregiments = get_regiments(player)
		local strname = ""
		if player:IsInGroup(4972535) then
			print("before1")
			local splitrank = player:GetRoleInGroup(4972535):split(" ")
			table.remove(splitrank,1)
			for i = 1,#splitrank do
				strname = strname..splitrank[i].." "
			end
		else
			strname = "Civilian"
		end
		local strreg = ""
		if player:GetRankInGroup(4972535) < 22 then
			if #plrregiments > 1 then
				for i = 1,#plrregiments do
					if i < #plrregiments then
						strreg = strreg.."["..plrregiments[i].TAG.."] - "
					else
						strreg = strreg.."["..plrregiments[i].TAG.."]"
					end
				end
			elseif #plrregiments == 1 then
				strreg = "["..plrregiments[1].TAG.."] - "..player:GetRoleInGroup(plrregiments[1].ID)
			else
				if player:IsInGroup(4972535) then
					strreg = "Enlisted Personnel"
				else
					strreg = "Civilian"
				end
			end
			else
			strreg = "HEADQUARTERS"
		print("check3")
		end
		print(strreg)
		if (player:GetRankInGroup(4780049) >= 246) then
			strreg = strreg.."["..player:GetRoleInGroup(4780049).."]"
		end
		if (player:GetRankInGroup(5000086) >= 246) then
			strreg = strreg.."["..player:GetRoleInGroup(5000086).."]"
		end
		if(player.UserId == 1108228838) then
			strreg = "BA | Creator Program ⭐️"
		end

	print("Changed")
script.Parent.Parent.Landing.Player_Info.Regiment.Text = strreg

So I have this script which I debugged but it works perfectly in studio but not in game, any idea what might cause it?

Thank you for your time :slight_smile:

Does it have any error in the Developer console? You can open the Developer console by clicking F9 in-game, then click “Server” and look for an error there

Hi cub :wave:

Is anything being printed at all? I’ve noticed that on the first line you’re printing “f”, if that isn’t being printed then your script isn’t being executed.

To solve this, make sure your script isn’t disabled and your script isn’t being destroyed somewhere in the runtime. Also ensure that the script class is able to run on the environment that it’s in, for example LocalScripts won’t work in the workspace, and Scripts won’t run in client environments.

Check to see whether your script is being executed, then we can progress with some debugging.

Hope this helps,
-Tom :slight_smile:

1 Like

Hey tom! Nice to see you but anyways,
The script is a local script and it only prints until “Check2”,
Additionally, the script doesn’t print any errors whatsoever @Motivatial

Nevermind, I found a solution thanks to your answer.
I’ve put the local script in a place where it’ll run sooner.