Surface Gui not displaying for NPC suspicion system?

howdy roblox devs! does anyone know why the heck my gui isn’t displaying on this part? i’m trying to make an npc suspicion system and i really have no idea why it’s not displaying, maybe this is a dumb question. anyways here’s a pic of what is generated during the game:
image
(it’s the little black bar beneath the npc) and here’s the part of the script making the bar:

local NPC = script.Parent
local head = NPC:WaitForChild("Head")
local rootPart = NPC:WaitForChild("HumanoidRootPart")
local detectionRange = 50 -- Adjust the detection range as needed
local fieldOfViewThreshold = 0.5 -- Adjust the field of view threshold as needed

local suspicionAmount = 0

local suspicionMeter = Instance.new("Part")
suspicionMeter.Size = Vector3.new(7.5, 0.25, 0.5)
suspicionMeter.BrickColor = BrickColor.new("Really black")
suspicionMeter.CanCollide = false
suspicionMeter.Position = rootPart.Position + rootPart.CFrame.UpVector * -2.875 + rootPart.CFrame.LookVector * 1.5

local susGui = Instance.new("SurfaceGui")
susGui.Face = Enum.NormalId.Top
susGui.Parent = suspicionMeter

local susFrame = Instance.new("Frame")
susFrame.Size = UDim2.new(0,0,0,0)
susFrame.BackgroundColor3 = Color3.new(255,255,0.3)
susFrame.Parent = susGui

local susWeld = Instance.new("WeldConstraint")
susWeld.Part0 = suspicionMeter
susWeld.Part1 = rootPart
susWeld.Parent = suspicionMeter
suspicionMeter.Parent = NPC

any help is appreciated! also if anyone has ideas on how to make a unique and cool detection system i would love to hear it! whether it’s using parts for detection or rays or something else i’d like to hear your take on things!

ps i have confirmed that the problem is with the gui or frame, not the part

I mean… You set the size of the frame to UDim2.new(0,0,0,0). Perhaps that is the issue?

uhhhh… yeah that was it, i think im just an idiot. thanks so much i could not find out what the frick it was haha. it cause the initial susipcion was supposed to be zero, and it should’ve gone up with susFrame.Size = UDim2.new(1,0,suspicionAmount,0). thank you, i’ll try not to make another STUPID mistake like this again!

edit: the sus value wasn’t changing correctly cause i reversed it in this statement (now fixed)

if char:FindFirstChild(raycastResult.Instance) then
	suspicionAmount = math.clamp(suspicionAmount - 0.01,0,1)
else
	suspicionAmount = math.clamp(suspicionAmount + 0.01,0,1)
end
2 Likes

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