In my game i need to tween a lot of billboardGui's size when you're close to them. I made this script to handle them all, but the first one is working not the others, do you possibly need to use a coroutine? I've heard they might be related to this problem. Can someone give a brief answer explaining in detail?
local Player = game.Players.LocalPlayer
local CheckItem = require(script.CheckItem)
local Char = Player.CharacterAdded:Wait()
local TweenItem = require(script.TweenItem)
function checkDist(part1, part2)
if typeof(part1) ~= Vector3 then part1 = part1.Position end
if typeof(part2) ~= Vector3 then part2 = part2.Position end
return (part1 - part2).Magnitude
end
local function tweenStuffOut(item)
if CheckItem.Check(item) == true then
local Expandation = TweenItem.changeSize(1, 1, item)
Expandation:Play(
)
end
end
local function tweenStuffIn(item)
if CheckItem.Check(item) == true then
local Expandation = TweenItem.changeSize(0, 0, item)
Expandation:Play()
end
end
local function Run(realItem)
while wait() do
if checkDist(Char.HumanoidRootPart, realItem.Parent.Parent) <= 20 then
print("close")
tweenStuffOut(realItem)
else
tweenStuffIn(realItem)
end
end
end
-- Main Billboards
Run(workspace.Applications.BankShop.Step.BillboardGui.TextLabel)
Run(workspace.Applications.WeaponShop.StepPart.BillboardGui.TextLabel)
Run(workspace.Applications.PetShop.Step.BillboardGui.TextLabel)
Run(workspace.Applications.DailyGroupReward.StepPart.BillboardGui.TextLabel)

1 comment
Both of the answers work, i don't know which thing to pick. But I've heard spawn(function() is deprecated. I'll accept raid6n's answer, but I'll upvote tizzel40's answer :D