I’m trying to make an enemy for my tower defense game that can go underground and teleport farther into the map to escape towers. However, the teleportation doesn’t work for some reason.
Script that makes the monster go underground and (not yet) teleport:
repeat
task.wait()
until (script.Parent):IsA("Model")
if script.Parent.Name == "Umbra Monstrum" then
local hrp = script.Parent:WaitForChild("HumanoidRootPart")
local ts = game:GetService("TweenService")
local pathystuff = (game.Workspace:WaitForChild("PathWay"))
local tweeninfo = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false)
local hum = script.Parent:WaitForChild("Humanoid")
local isunderground = hum.Parent:WaitForChild("IsUnderground")
local path = script.Parent:WaitForChild("ChosenPath")
local currentyeeyee = hum.Parent:WaitForChild("Ajajajajaja")
local pathy = pathystuff:WaitForChild(path.Value)
local merge = pathystuff:WaitForChild("Merge")
local tableofstuff = {}
for i, v in pairs(pathy:GetChildren()) do
table.insert(tableofstuff, v)
end
for i, v in pairs(merge:GetChildren()) do
table.insert(tableofstuff, v)
end
isunderground.Value = false
hum.HealthChanged:Connect(function(health)
local max = hum.MaxHealth
if health*2 == max then
hum.WalkSpeed = 0
local animcontroller = hum:WaitForChild("Animator")
local anim = hum:WaitForChild("Shadow")
local shadowanimation = animcontroller:LoadAnimation(anim)
shadowanimation.Priority = Enum.AnimationPriority.Action3
shadowanimation:Play()
task.wait(2)
local tween = ts:Create(hrp, tweeninfo, {CFrame = hrp.CFrame * CFrame.new(0, -8, 0)})
hrp.Anchored = true
tween:Play()
print("yee yee")
tween.Completed:Wait()
isunderground.Value = true
hrp.Anchored = false
print(pathystuff)
print(currentyeeyee.Value) --Prints 4
local findyfind = table.find(tableofstuff, tostring(currentyeeyee.Value))
print(findyfind) --Prints nil (for some reason), there is only from 1-4
end
end)
task.wait(5)
hum.Health = 3 --Test purposes only
end
There’s a script that changes Ajajajajaja (pathfinding script):
repeat
task.wait()
until (script.Parent):IsA("Model")
local col = require(game.ServerStorage:WaitForChild("Collisions"))
local inunderground
local hum = script.Parent:WaitForChild("Humanoid")
local hrp = script.Parent:WaitForChild("HumanoidRootPart")
if script.Parent.Name == "Umbra Monstrum" then
inunderground = script.Parent:WaitForChild("IsUnderground")
end
local CODINGISHARD
local currentyeeyee = hum.Parent:WaitForChild("Ajajajajaja")
local path = script.Parent:WaitForChild("ChosenPath")
local pathway = game.Workspace:WaitForChild("PathWay")
local chosenPath = pathway:WaitForChild(path.Value)
local merged = pathway:WaitForChild("Merge")
local chosenchildren = chosenPath:GetChildren()
local mergedchildren = merged:GetChildren()
local pathpoints = {}
local undergroundpath = (game.Workspace:WaitForChild("UndergroundPathWay")):GetChildren()
col.SetPartToGroup(undergroundpath, "Paths and Doorways")
for i, v in pairs(chosenchildren) do
table.insert(pathpoints, v)
end
for i, v in pairs(mergedchildren) do
table.insert(pathpoints, v)
end
CODINGISHARD = 0
for i, v in pairs(pathpoints) do
if i == 5 then
break
end
CODINGISHARD = i
currentyeeyee.Value = i
print(currentyeeyee.Value)
inunderground.Changed:Connect(function(val)
CODINGISHARD = i+1
if CODINGISHARD == 5 then
CODINGISHARD = 4
end
end)
if i~=CODINGISHARD then
continue
end
hum:MoveTo(v.Position, v)
hum.MoveToFinished:Wait()
if (hrp.Position - v.Position).Magnitude > 1 and (hrp.Position - v.Position).Magnitude < (hrp.Position - (pathpoints[i]).Position).Magnitude then
hum:MoveTo(v.Position, v)
hum.MoveToFinished:Wait()
end
end
Thanks so much