In my game I need to tween stuff when you're close to the things, and the first loop is only running, not the other loop?

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 Run = coroutine.wrap(function(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)
	
Run(workspace.Excalibur.Model.Model.BladeMain.BillboardGui.TextLabel)

1 comment

0

doesn't coroutine.wrap just resume a function instead of creating a new one