Localscript not running passed first lines

  1. What do you want to achieve?
    I want my script to run, it confused me for a while.
  2. What is the issue? Include screenshots / videos if possible!
    alrighty so my issue is in my radargui, I have a localscript inside the gui but it only runs the first 6 lines! when I remove the lines it runs the rest of the script but I need the variables for it to not error.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have put prints everywhere in my code to see where the issue lied, line 8 and below are void, not running at all.
local player = game.Players.LocalPlayer
local character = player.CharacterAdded:wait()
local root = character:WaitForChild("HumanoidRootPart")
local main = script.Parent:WaitForChild("Main")
local area = 200
local maxParts = 100

print("This print doesnt run.") -- this print doesnt run, the lines above it cause some issue but idk.

function buildMap()
	main:ClearAllChildren()
	local region = Region3.new(root.CFrame.p-Vector3.new(area,10,area),root.CFrame.p+Vector3.new(area,10,area))
	local parts = workspace:FindPartsInRegion3WithIgnoreList(region,{character},maxParts)

	for _,v in pairs(parts) do
		local part = Instance.new("Frame",main)
		part.Size = UDim2.new(0,v.Size.X,0,v.Size.Z)
		part.BackgroundColor3 = v.Color
		local CF = CFrame.new(root.CFrame.p)
		local pos = CF:toObjectSpace(v.CFrame)
		local realPos = CFrame.new(pos.X+(main.Size.X.Offset/2),0,pos.Z+(main.Size.Y.Offset/2))
		part.Position = UDim2.new(0,realPos.X-part.Size.X.Offset/2,0,realPos.Z-part.Size.Y.Offset/2)
		part.ZIndex = v.Position.Y
	end	
end

game:GetService("RunService").RenderStepped:connect(function()
	buildMap()
end)

image_2022-12-23_190350613

If the player’s character exists when this code runs, it will wait until the player dies again.

Change this to:

local character = player.Character or player.CharacterAdded:Wait()

If this doesn’t solve your issue, then one of the Instances above (HumanoidRootPart or Main) aren’t being replicated to the client

1 Like

Thank you so much!
I cant believe I’ve been stuck on this for an hour and a half!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.