Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I check if player does not have light inside his torso already?

Hello, I need help. I don't know how to check if player does not have light inside his torso already but it won't run the function, it seems like it can't check if its in it.

The script is:

return function()
script.Parent.Touched:Connect(function(t)
		if not t.Parent.Torso.Glow then
local glow = Instance.new("PointLight")
glow.Name = "Glow"
glow.Parent = t.Parent.Torso
glow.Range = script.Parent.Range.Value or 16
glow.Color = script.Parent.GlowColor.Value or Color3.fromRGB(255, 255, 255)
end
end)
end

Thanks for help!

1 comment

0

Are you requiring the module script? Are you receiving any errors? If so, please post your code.

1 answer

You should detect something not exist by using FindFirstChild. Because if they detect nothing, they return nil.

Example:

local Glow = t.Parent.Torso:FindFirstChild("Glow")

if Glow == nil then
	-- do what you want
end

1 comment

0

Alright, thanks a lot!

This discussion is preserved as it was. New answers, comments, and votes are closed.