Hi, I’m making an E Prompt button that if you walk near every part named ‘Haul’ then it will enable the billboardgui. It’s not working although it’s cloned to that part. I used FindFirstChild in a loop and that doesn’t work
Code
local EPrompt = script.EPrompt
local EWall = EPrompt:WaitForChild("EWall")
EWall.Enabled = false
local ContextActionService = game:GetService("ContextActionService")
local Plr = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")
local ebuttons = {}
local function AddE_buttons(name)
for _,haul in ipairs(workspace:GetChildren()) do
if haul:IsA("Part") and haul.Name == name then
table.insert(ebuttons, haul)
end
end
end
AddE_buttons("Haul")
for _,D in ipairs(ebuttons) do
local newWall = EWall:Clone()
newWall.Parent = D
while true do
for _,E in ipairs(ebuttons) do
E.EWall.Enabled = false
local Mag = (Plr.Position-E.Position).Magnitude
if Mag < 15 then
E:FindFirstChild("EWall").Enabled = true
elseif Mag > 15 then
E:FindFirstChild("EWall").Enabled = false
end
if E.Name == "Haul" then
local R = print("OBJECT FOUND")
end
wait()
end
end
end
Hi. Are you sure “Haul” parts are directly parented to the workspace? Since you call workspace:GetChildren() once maybe the parts still don’t exist before the while loop starts.
If this is not the problem, add print checks so it’s easier to spot the issue.
Line 21, the end keyword was missplaced. The script now works perfectly
local EPrompt = script.EPrompt
local EWall = EPrompt:WaitForChild("EWall")
EWall.Enabled = false
local ContextActionService = game:GetService("ContextActionService")
local Plr = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")
local ebuttons = {}
local function AddE_buttons(name)
for _,haul in ipairs(workspace:GetChildren()) do
if haul:IsA("Part") and haul.Name == name then
table.insert(ebuttons, haul)
end
end
end
AddE_buttons("Haul")
for _,D in ipairs(ebuttons) do
local newWall = EWall:Clone()
newWall.Parent = D
end -- !!!!!!!!
while true do
for _,E in ipairs(ebuttons) do
E.EWall.Enabled = false
local Mag = (Plr.Position-E.Position).Magnitude
if Mag < 15 then
E:FindFirstChild("EWall").Enabled = true
elseif Mag > 15 then
E:FindFirstChild("EWall").Enabled = false
end
if E.Name == "Haul" then
local R = print("OBJECT FOUND")
end
wait()
end
end
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local EWall = ReplicatedStorage:WaitForChild('EWall')
local ContextActionService = game:GetService('ContextActionService')
local Plr = game.Players.LocalPlayer.Character:WaitForChild('HumanoidRootPart')
local ebuttons = {}
local function AddE_buttons(name)
for _,haul in ipairs(workspace:GetChildren()) do
if haul.Name == 'Haul' then
table.insert(ebuttons, haul)
end
end
end
AddE_buttons()
wait(0.2)
for _,D in ipairs(ebuttons) do
local newWall = EWall:Clone()
newWall.Parent = D
while true do
for _,E in ipairs(ebuttons) do
E.EWall.Enabled = false
local Mag = (Plr.Position-E.Position).Magnitude
if Mag < 11 then
E:FindFirstChild('EWall').Enabled = true
elseif Mag > 11 then
E:FindFirstChild('EWall').Enabled = false
end
end
wait()
end
end
Instead of cloning the GUI multiple times, you could change its Adornee instead which I find to be much more efficient.
Place the billboard GUI in StarterGui and change its Adornee when a player is within proximity of a specific part (such as “Haul”).