E Prompt button billboardgui doesn't clone to every part that is named 'Haul'

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

I think you didn’t specify what name is, so:

if haul:IsA("Part") and haul.Name == "Haul" then

1 Like

i wrote haul in capitalization ‘Haul’

same name as part.

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.

‘Haul’ parts are already in the workspace

Line 21, the end keyword was missplaced. The script now works perfectly :ok_hand:

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

Almost done

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

doesn’t go to every part though

Yes this is the issue I’m trying to point, the for loop shouldn’t include the while loop. You have to end it before the while loop starts.

At least it worked as expected when I replicated it on studio.

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”).

1 Like