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
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
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
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)()
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)()
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