Overview
Hello, Everyone. I am working on an Obby and wanted to improve how projectile spawns.
- What does the code do, and what are you unsatisfied with?
So, the bullet is cloned from the ServerStorage and parented and positioned in the cannon barrel. Then, it is Tweened to the target position on the opposite side. What I am unsatisfied with is I want a way for it to spawn to each cannon one at a time. - What potential improvements have you considered?
I tried running RunService, but I don’t think it’s good for what I’m trying to do. I tried it at first, but I stumbled. - How (specifically) do you want to improve the code?
local ServerStorage = game:GetService("ServerStorage")
local cannonFolder = workspace.MarioBullets.Cannons
local bullet = ServerStorage:WaitForChild("Bullet")
local Barrel = cannonFolder.CannonModel.Barrel
local ts = game:GetService("TweenService")
local ti = TweenInfo.new(1,Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, 0, false)
local function SpawnBullet(Object: Part, target: Part)
local cloneBullet = bullet:Clone()
cloneBullet.Parent = workspace
game:GetService("Debris"):AddItem(cloneBullet,1)
cloneBullet.Position = Object.Position
local tween = ts:Create(cloneBullet, ti, {Position = target.Position}):Play()
end
while wait(2) do
for _, v in pairs(cannonFolder:GetChildren()) do
-- Get the barrel in each cannon model and spawnBullet
for _, part in pairs(v:GetChildren()) do
if part.Name == "Barrel" then
SpawnBullet(part, v.TargetPosition)
else
continue
end
end
end
end
Video :
Folder the models in:
