Ball and Label Spawn

--[[ Tell balls (count) to shoot off at game start from "StartPen"

]]--
local _owners = require( script:GetCustomProperty("ListPlayers") )
local _ballSpawn = Vector3.New(-5220,131,1900)
local propBallTemplate = script:GetCustomProperty("BallTemplate") -- BWB
local propLabelTemplate = script:GetCustomProperty("LabelTemplate")--BWBLabel
local _ballsFolder = World.FindObjectByName("BallsFolder")
local _ballList = nil

-- spawn x balls and labels
for a=1, #_owners do
    Task.Wait(.13)
    _G["_myBall"..a] = World.SpawnAsset(propBallTemplate, {position = _ballSpawn})
    _G["_myBall"..a]:SetVelocity(Vector3.RIGHT * 10)
    --_G["_myBall"..a.."_owner"] = _owners[a][1]
    _G["_myBall"..a]:SetNetworkedCustomProperty("Owner", a)
    
    --print(_G["_myBall"..a]:GetCustomProperty("Owner"))
    -- create label
    _G["_myLabel"..a] = World.SpawnAsset(propLabelTemplate, {position = _ballSpawn})
    _G["_myLabel"..a]:Follow(_G["_myBall"..a])
    _G["_myLabel"..a]:SetNetworkedCustomProperty("Owner", _owners[a][1])
end

UI.PrintToScreen("5")
Task.Wait(1)
UI.PrintToScreen("4")
Task.Wait(1)
UI.PrintToScreen("3")
Task.Wait(1)
UI.PrintToScreen("2")
Task.Wait(1)
UI.PrintToScreen("1")
Task.Wait(1)
UI.PrintToScreen("GO!")

--[[ METHOD FROM FOLDER
_ballList = _ballsFolder:GetChildren()
for _, _ball in ipairs(_ballList) do
    --print(_ball.name) print(_ball:GetVelocity())
    _ball:SetVelocity(Vector3.FORWARD * 1000)
end--]]


-- BLAST OFF ALL BALLS
for a=1, #_owners do
    _G["_myBall"..a]:SetVelocity(Vector3.FORWARD * 1000)
end


Task.Wait(1)

-- test getting name reference from specific ball
--print( _owners[_G["_myBall"..63]:GetCustomProperty("Owner")][1] )
--_G["_myBall"..63]:Destroy()
--_G["_myLabel"..63]:Destroy()

Latest Posts