Why wont my billboards clone?

Hello!

I am making a script which will clone a billboard into every part in a folder and animate it. However, it doesn’t clone

local TweenService = game:GetService(“TweenService”)

local function animateBillboard(bilboard, OpenOrClose)
if OpenOrClose == true then
TweenService:Create(bilboard, TweenInfo.new(.3), {Size = UDim2.new(12,0,12,0)}):Play()
else
TweenService:Create(bilboard, TweenInfo.new(.3), {Size = UDim2.new(0,0,0,0)}):Play()
end
wait(1)
end

for _, Locator in game.Workspace:WaitForChild(“Locators”):GetChildren() do
local LocatorBillboard = script.Template:Clone()
LocatorBillboard.Parent = Locator

if game.Players.LocalPlayer:DistanceFromCharacter(Locator.Position) < LocatorBillboard.MaxDistance then
animateBillboard(LocatorBillboard, false)
else
animateBillboard(LocatorBillboard, true)
end
end

Can anyone help me fix this?

Thanks!

1 Like

If you are using a LocalScript (which I think you are since you’re using WaitForChild), I think the problem you’re experiencing is due to the Locators not being present at the time the loop runs. Add a print(true) to the loop at the start for example and see if it shows up in the output, and if not, then that confirms the theory. I also have a solution to the problem in that case by adding:

workspace.Locators.ChildAdded:Connect(function(Locator)
—Copy and paste the code you have in your loop here
end)

But please do so after the end your loop for it to work correctly

1 Like

would i still need the for

_, Locator in game.Workspace:WaitFortChild(“Locators”):GetChildren() do

or not?

Thank you so much btw!

1 Like

Yes the loop will need to stay in case a Locator already exists :slightly_smiling_face:

1 Like

Thank you so much! ill test it.

1 Like

It works! Thank you so much.

But the billboards don’t animate. Whats the error with that?

local function animateBillboard(bilboard, OpenOrClose)
if OpenOrClose == true then
TweenService:Create(bilboard, TweenInfo.new(.3), {Size = UDim2.new(12,0,12,0)}):Play()
else
TweenService:Create(bilboard, TweenInfo.new(.3), {Size = UDim2.new(0,0,0,0)}):Play()
end
wait(1)
end

Most likely because you’re checking the distance only once in an if statement instead of a loop, but you’ll need to use coroutines to work correctly like so:

coroutine.wrap(function()
   while true do
   if game.Players.LocalPlayer:DistanceFromCharacter(Locator.Position) < LocatorBillboard.MaxDistance then
animateBillboard(LocatorBillboard, false)
else
animateBillboard(LocatorBillboard, true)
end
   task.wait(0)
end
end)()

Edit: Sorry I forgot to add the loop, lol but it’s fixed now. It’s late night where I live so a bit sleepy

1 Like

That is really confusing to add lol. ima try figure it out

Now its not showing up lol

local TweenService = game:GetService(“TweenService”)

local function animateBillboard(bilboard, OpenOrClose)
if OpenOrClose == true then
TweenService:Create(bilboard, TweenInfo.new(.3), {Size = UDim2.new(12,0,12,0)}):Play()
else
TweenService:Create(bilboard, TweenInfo.new(.3), {Size = UDim2.new(0,0,0,0)}):Play()
end
wait(1)
end

workspace.Locators.ChildAdded:Connect(function(Locator)
for _, Locator in game.Workspace:WaitForChild(“Locators”):GetChildren() do
local LocatorBillboard = script.Template:Clone()
LocatorBillboard.Parent = Locator

  coroutine.wrap(function()
  	while true do
  		if game.Players.LocalPlayer:DistanceFromCharacter(Locator.Position) < LocatorBillboard.MaxDistance then
  			animateBillboard(LocatorBillboard, false)
  		else
  			animateBillboard(LocatorBillboard, true)
  		end
  		task.wait(0)
  	end
  end)()

end
end)

To work correctly it needs to replace the if statement as it won’t be necessary anymore

1 Like

Which one?

local TweenService = game:GetService(“TweenService”)

local function animateBillboard(bilboard, OpenOrClose)
if OpenOrClose == true then
TweenService:Create(bilboard, TweenInfo.new(.3), {Size = UDim2.new(12,0,12,0)}):Play()
else
TweenService:Create(bilboard, TweenInfo.new(.3), {Size = UDim2.new(0,0,0,0)}):Play()
end
wait(1)
end

workspace.Locators.ChildAdded:Connect(function(Locator)
for _, Locator in game.Workspace:WaitForChild(“Locators”):GetChildren() do
local LocatorBillboard = script.Template:Clone()
LocatorBillboard.Parent = Locator

  coroutine.wrap(function()
  	while true do
  		if game.Players.LocalPlayer:DistanceFromCharacter(Locator.Position) < LocatorBillboard.MaxDistance then
  			animateBillboard(LocatorBillboard, false)
  		else
  			animateBillboard(LocatorBillboard, true)
  		end
  		task.wait(0)
  	end
  end)()

end
end)

What isn’t showing up by the way?

1 Like

Where the arrow is should be the billboard gui and tweens to max size, but nothing appears

If you want the arrow to change size proportional to how far away the camera is, then you need to use a different method that what we’re currently using so please confirm

1 Like

ok, ill send you an example of what i mean

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.