Text not changing (appearing)

Hello! I’m basically making a security scanner, which checks whether the player has weapons (tools) or not. Then, it changes the screen’s text.

However, it doesn’t change the text. Nothing appears, basically. I even tried removing the second part of the script (for i, v in pairs(characterTools)), but that didn’t help either.

local part = script.Parent
local statusText = part.Parent.Screen.SurfaceGui:WaitForChild("ImageLabel"):WaitForChild("Status")
local YESsound = part.Parent.Sound:WaitForChild("YES")
local NOsound = part.Parent.Sound:WaitForChild("NO")

local DEBOUNCE = false
local characterToolCount = 0

local function onPartTouched(otherPart)
	if DEBOUNCE == false then
		DEBOUNCE = true
		local humanoid = otherPart.Parent:FindFirstChild("Humanoid")

		if humanoid then
			local who = game.Players:FindFirstChild(otherPart.Parent.Name)
			local tools = who.Backpack:GetChildren()
			local characterTools = who.Parent:GetChildren()

			for i in pairs(tools) do
				if tonumber(#tools) >= 1 then
					statusText.Text = "YES"
					statusText.TextColor3 = Color3.fromRGB(170, 0, 0)
				elseif tonumber(#tools) == 0 then
					statusText.Text = "NO"
					statusText.TextColor3 = Color3.fromRGB(85, 255, 0)
				end
				break
			end
			for i, v in pairs(characterTools) do
				if v.ClassName == "Model" and v:FindFirstChild("AimPart") then
					characterToolCount += 1
				end
				if characterToolCount >= 1 then
					YESsound:Play()
					wait(2)
					statusText.Text = ""
				elseif characterToolCount == 0 and tonumber(#tools) == 0 then
					NOsound:Play()
					wait(2)
					statusText.Text = ""
				elseif characterToolCount == 0 and tonumber(#tools) >= 1 then
					YESsound:Play()
					wait(2)
					statusText.Text = ""
				end
				break
			end
		end
		
		characterToolCount = 0
		wait(1)
		DEBOUNCE = false
	end
end

part.Touched:Connect(onPartTouched)

is anything popping up in the output?

Try adding in some print statements to check the logic of the if statements

1 Like

A weird thing is that it worked before, and I haven’t changed much code that affects the text itself. The sounds also play. Basically everything works fine, except the text itself.

What is

local characterTools = who.Parent:GetChildren()

supposed to represent? In this context this gets the players within the game (since it gets the parent of the Player “who”, and gets the parent’s children (all players).

1 Like

Yeah I noticed that now as well, fixed it. Still doesn’t help though.

You don’t have to iterate through all the tools, that is completely useless. You can just do remove for i in pairs(tools) do, as well as break and the end of the for loop.

1 Like

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