So, im making a system for opening vents & its very simple, but for some reason its saying Nil for Triggered. I have never seen this before. Ive reloaded Roblox Studio, checked for any misspeals, and I have no idea what else I can do.
CODE:
local Folder = script.Parent.Vents
for _, v in pairs(Folder:GetChildren()) do
local Model = v
local Prompt = Model:FindFirstChild("Prompt")
local VelocityForVentPiece = Model:FindFirstChild("LinearVelocity")
local IsOpen = false
Prompt.Triggered:Connect(function() -- Why is it getting Nil for Triggered??
if IsOpen == false then
IsOpen = true
Prompt.Enabled = false
VelocityForVentPiece.Enabled = true
task.wait(0.2)
VelocityForVentPiece.Enabled = false
else
print("Opened, why is this showing up??")
end
end)
end
Here is a screenshot of it just in case you need it
âAttempt to index nil with âTriggeredââ actually means the value of Prompt is nil. This is because the model doesnât contain your prompt, so :FindFirstChild() returns nil due to its failure to locate a child named Prompt. A very simple fix would be calling :FindFirstChild() for both MainVentPart and Prompt within the model instead:
local Prompt = Model:FindFirstChild'MainVentPart':FindFirstChild'Prompt'
Oh, and as @NormalDeveloperX stated, :FindFirstChildOfClass() may be convenient here since it accounts for unexpected name changes in both objects:
local Prompt = Model:FindFirstChildOfClass'UnionOperation':FindFirstChildOfClass'ProximityPrompt'
The answer above is correct; you just need to adjust the path to the button and Velocity :
local Folder = script.Parent.Vents
for _, v in pairs(Folder:GetChildren()) do
local Model = v
local Prompt = Model:FindFirstChild("MainVentPart"):FindFirstChild("Prompt")
local VelocityForVentPiece = Model:FindFirstChild("MainVentPart"):FindFirstChild("LinearVelocity")
local IsOpen = false
Prompt.Triggered:Connect(function() -- Why is it getting Nil for Triggered??
if IsOpen == false then
IsOpen = true
Prompt.Enabled = false
VelocityForVentPiece.Enabled = true
task.wait(0.2)
VelocityForVentPiece.Enabled = false
else
print("Opened, why is this showing up??")
end
end)
end
If itâs that much a nuisance, you can directly call :FindFirstDescendant() on the model which searches all descendants of an object for the instance with the specified name rather than just direct children: