-
What do you want to achieve? I am making a tower defense game and currently doing the enemy system
-
What is the issue? Script 1: It doesnt move the enemy. Script 2: Tweening doesnt move it on all the positions only on the first one.
Script 1
function spawnEnemy(enemyType)
if game:GetService('ReplicatedStorage'):FindFirstChild('Enemies'):FindFirstChild(enemyType) then
local enemy = game:GetService('ReplicatedStorage'):FindFirstChild('Enemies'):FindFirstChild(enemyType):Clone()
enemy.Parent = workspace.Map.Enemies
enemy:SetPrimaryPartCFrame(workspace.Map.Markers.start.CFrame)
end
end
function run(code)
for line in code:gmatch("([^\n]*)\n?") do
local args = split(line)
if args[1] == 'wait' then
wait(args[2])
elseif args[1] == 'spawn' then
spawnEnemy(args[2])
end
end
end
function split(line)
local args = {}
for word in string.gmatch(line,[[([^(),]+)]]) do
table.insert(args,#args+1,word)
end
return args
end
function getSpawnOrder(wave)
wave = tostring(wave)
local orderscriptUrl = 'http://raw.githubusercontent.com/PatriikPlays/scpTowerDefence/main/spawnOrder/waves/'..wave..'/order.oscript'
local orderscriptFile = game:GetService('HttpService'):GetAsync(orderscriptUrl)
return orderscriptFile
end
run(getSpawnOrder(1))
Script 2
local tweenService = game:GetService('TweenService')
local cf = nil
local ammountOfPositions = 0
for i,v in ipairs(workspace.Map.Markers.Positions:GetChildren()) do
if v:IsA('BasePart') then
ammountOfPositions = ammountOfPositions + 1
end
end
local info = TweenInfo.new(
10/script.Parent.Speed.Value,
Enum.EasingStyle.Linear,
Enum.EasingDirection.In,
0,
false,
0
)
function tweenModel(model,CF)
local CFrameValue = Instance.new("CFrameValue")
CFrameValue.Value = model:GetPrimaryPartCFrame()
CFrameValue:GetPropertyChangedSignal("Value"):connect(function()
model:SetPrimaryPartCFrame(CFrameValue.Value)
end)
local tween = tweenService:Create(CFrameValue, info, {Value = CF})
tween:Play()
tween.Completed:connect(function()
CFrameValue:Destroy()
end)
end
cf = script.Parent:GetPrimaryPartCFrame() + Vector3.new(0,100,0)
print(ammountOfPositions)
for i=1,ammountOfPositions do
tweenModel(script.Parent,workspace.Map.Markers.Positions:FindFirstChild('position'..i).CFrame)
end