helloo, there’s this local script that doesn’t work, idk why. if i remove the workspace.childadded thing to find the specific workspace child it works. but i need to use that child!!
local player = game.Players.LocalPlayer
local ColorCorrection = game.Lighting.ColorCorrection
local originalColor = ColorCorrection.TintColor
local RedColor = Color3.fromRGB(255, 0, 0)
workspace.ChildAdded:Connect(function()
wait(1)
local children = workspace:GetChildren()
if children:FindFirstChild("distance") then
local npc = children
while task.wait() do
-- just stuff (which i verified works)
end
end
end)
why gettin children without the parameter???
ChildAdded already returns the object being added in the parameters, you could’ve just use that
you’re also checkin the table which doesn’t get the children you’re trying to find, GetChildren only returns a table of the children in that case becoming a table.
local player = game.Players.LocalPlayer
local ColorCorrection = game.Lighting.ColorCorrection
local originalColor = ColorCorrection.TintColor
local RedColor = Color3.fromRGB(255, 0, 0)
workspace.ChildAdded:Connect(function(child)
wait(1)
--local children = workspace:GetChildren() < This only returns a table
if child:FindFirstChild("distance") then
local npc = child
while task.wait() do
-- just stuff (which i verified works)
end
end
end)
You’re already connecting an event that waits to fire (in that word simply runs that each time a child is added to workspace) and run the code inside so there’s no need to make any extra lines that constantly check for it
What i meant by event is exactly this one workspace.ChildAdded:Connect(function(child)