so, for whatever reason this script says this part doesn’t have a parent when it does, I have no idea why this is happening, please help!
script:
for _, Prompt: ProximityPrompt in pairs(ExecutePrompts) do
print(Prompt:GetFullName())
if Prompt.Parent then
print("No parent")
continue
end
if (Prompt.Parent.Position - RootPart.Position).Magnitude > 2 then
Prompt:Destroy()
end
end
Did you adjust the code to what @SeargentAUS had recommended? if so then can you show us more of the script, or at least the hierarchy of the prompts so we can have a better idea of the situation
for _, Prompt: ProximityPrompt in pairs(ExecutePrompts) do
print(Prompt.Parent)
if not Prompt.Parent then
print("No parent")
continue
end
if (Prompt.Parent.Position - RootPart.Position).Magnitude > 2 then
Prompt:Destroy()
end
end
local FrontCast = Raycast(RootPart.Position, RootPart.Position + (RootPart.CFrame.LookVector * 2.5),{})
if FrontCast and FrontCast.Instance.Parent:FindFirstChildWhichIsA("Humanoid") and FrontCast.Instance.Parent:FindFirstChildWhichIsA("Humanoid").Health > 0 then
local looking = checkTargetView(FrontCast.Instance.Parent)
local TheirRootPart = FrontCast.Instance.Parent:FindFirstChildWhichIsA("Humanoid").RootPart
if looking and TheirRootPart then
if TheirRootPart:FindFirstChild("ExecutePrompt") == nil then
local NewExecutePrompt = Instance.new("ProximityPrompt",FrontCast.Instance.Parent:FindFirstChildWhichIsA("Humanoid").RootPart)
NewExecutePrompt.ActionText = "Execute"
NewExecutePrompt.RequiresLineOfSight = false
NewExecutePrompt.Name = "ExecutePrompt"
table.insert(ExecutePrompts,NewExecutePrompt)
end
end
end
I figured out a solution. idk why this was happening
for i, V: ProximityPrompt in pairs(ExecutePrompts) do
local Prompt = ExecutePrompts[i]
if not Prompt.Parent then
print("No parent")
continue
end
if (Prompt.Parent.Position - RootPart.Position).Magnitude > 3 then
table.remove(ExecutePrompts,table.find(ExecutePrompts,Prompt))
Prompt:Destroy()
end
end
Ah, glad you figured it out! I believe it was because the variable for the prompt still existed in the table, and so when the script looped through the table it would loop through the empty variable and not find an instance paired to it.
If you already knew this than I apologize, I am just kind of thinking out loud if you know what I mean