ok so i know bodygyro is deprecated so if i were to use bodygryo.D what would i replace it with
local SererStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local events = ReplicatedStorage:WaitForChild("Events")
local spawnTowerEvent = events:WaitForChild("SpawnTower")
local animateTowerEvent = events:WaitForChild("AnimateTower")
local tower = {}
local function FindNeartestTarget(newTower)
local maxDistance = 25
local nearestTarget = nil
for i, target in ipairs(workspace.Mobs:GetChildren()) do
local distance = (target.HumanoidRootPart.Position - newTower.HumanoidRootPart.Position).Magnitude
if distance < maxDistance then
print(target.Name, "is nearest target found so far")
nearestTarget = target
maxDistance = distance
end
end
return nearestTarget
end
function tower.Attack(newTower)
local target = FindNeartestTarget(newTower)
if target and target:FindFirstChild("Humanoid") and target.Humanoid.Health > 0 then
local targetCFrame = CFrame.lookAt(newTower.HumanoidRootPart.Position, target)
newTower.HumanoidRootPart.BodyGyro.CFrame = targetCFrame
animateTowerEvent:FireAllClients(newTower, "Attack")
target.Humanoid:TakeDamage(25)
end
task.wait(1)
tower.Attack(newTower)
end
function tower.Spawn(player, name, cframe)
local towerExists = ReplicatedStorage.Towers:FindFirstChild(name)
if towerExists then
local newTower = towerExists:Clone()
newTower.HumanoidRootPart.CFrame = cframe
newTower.Parent = workspace.Towers
local bodyGyro = Instance.new("AlignOrientation")
bodyGyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
bodyGyro.D = 0
bodyGyro.CFrame = newTower.HumandoidRootPart.CFrame
bodyGyro.Parent = newTower.HumanoidRootPart
for i, object in ipairs(newTower:GetDescendants()) do
if object:IsA("BasePart") then
object.CollisionGroup = "Towers"
end
end
coroutine.wrap(tower.Attack)(newTower)
else
warn("Requested tower does not exist")
end
end
spawnTowerEvent.OnServerEvent:Connect(tower.Spawn)
return tower
local SererStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local events = ReplicatedStorage:WaitForChild("Events")
local spawnTowerEvent = events:WaitForChild("SpawnTower")
local animateTowerEvent = events:WaitForChild("AnimateTower")
local tower = {}
local function FindNeartestTarget(newTower)
local maxDistance = 25
local nearestTarget = nil
for i, target in ipairs(workspace.Mobs:GetChildren()) do
local distance = (target.HumanoidRootPart.Position - newTower.HumanoidRootPart.Position).Magnitude
if distance < maxDistance then
print(target.Name, "is nearest target found so far")
nearestTarget = target
maxDistance = distance
end
end
return nearestTarget
end
function tower.Attack(newTower)
local target = FindNeartestTarget(newTower)
if target and target:FindFirstChild("Humanoid") and target.Humanoid.Health > 0 then
newTower.Humanoid:MoveTo(newTower.HumanoidRootPart.Position)
animateTowerEvent:FireAllClients(newTower, "Attack")
target.Humanoid:TakeDamage(25)
end
task.wait(1)
tower.Attack(newTower)
end
function tower.Spawn(player, name, cframe)
local towerExists = ReplicatedStorage.Towers:FindFirstChild(name)
if towerExists then
local newTower = towerExists:Clone()
newTower.HumanoidRootPart.CFrame = cframe
newTower.Parent = workspace.Towers
for i, object in ipairs(newTower:GetDescendants()) do
if object:IsA("BasePart") then
object.CollisionGroup = "Towers"
end
end
coroutine.wrap(tower.Attack)(newTower)
else
warn("Requested tower does not exist")
end
end
spawnTowerEvent.OnServerEvent:Connect(tower.Spawn)
return tower
BodyGyro was superceded by AlignOrientation a few years ago, the big difference between them being that AlignOrientation requires an Attachment to function properly, while BodyGyro does not.
AlignOrientation maintains much of the same functions as BodyGyro, however BodyGyro.D doesnt appear to have any replacements. BodyGyro.P does however, with it being AlignOrientation.Responsiveness.
Are you aware that you still have access to body gyros or do you just not want deprecated objects in your game? if you don’t know how to access it then just do the Instace.new(“Instance”) command.
This should fix the issue with that, lmk if it works.
local SererStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local events = ReplicatedStorage:WaitForChild("Events")
local spawnTowerEvent = events:WaitForChild("SpawnTower")
local animateTowerEvent = events:WaitForChild("AnimateTower")
local tower = {}
local function FindNeartestTarget(newTower)
local maxDistance = 25
local nearestTarget = nil
for i, target in ipairs(workspace.Mobs:GetChildren()) do
local distance = (target.HumanoidRootPart.Position - newTower.HumanoidRootPart.Position).Magnitude
if distance < maxDistance then
print(target.Name, "is nearest target found so far")
nearestTarget = target
maxDistance = distance
end
end
return nearestTarget
end
function tower.Attack(newTower)
local target = FindNeartestTarget(newTower)
if target and target:FindFirstChild("Humanoid") and target.Humanoid.Health > 0 then
newTower.HumanoidRootPart.CFrame = CFrame.lookAt(newTower.HumanoidRootPart.Position, target) -- Actually LOOK at the target
newTower.Humanoid:MoveTo(newTower.HumanoidRootPart.Position)
animateTowerEvent:FireAllClients(newTower, "Attack")
target.Humanoid:TakeDamage(25)
end
task.wait(1)
tower.Attack(newTower)
end
function tower.Spawn(player, name, cframe)
local towerExists = ReplicatedStorage.Towers:FindFirstChild(name)
if towerExists then
local newTower = towerExists:Clone()
newTower.HumanoidRootPart.CFrame = cframe
newTower.Parent = workspace.Towers
for i, object in ipairs(newTower:GetDescendants()) do
if object:IsA("BasePart") then
object.CollisionGroup = "Towers"
end
end
coroutine.wrap(tower.Attack)(newTower)
else
warn("Requested tower does not exist")
end
end
spawnTowerEvent.OnServerEvent:Connect(tower.Spawn)
return tower
local SererStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local events = ReplicatedStorage:WaitForChild("Events")
local spawnTowerEvent = events:WaitForChild("SpawnTower")
local animateTowerEvent = events:WaitForChild("AnimateTower")
local tower = {}
local function FindNeartestTarget(newTower)
local maxDistance = 25
local nearestTarget = nil
for i, target in ipairs(workspace.Mobs:GetChildren()) do
local distance = (target.HumanoidRootPart.Position - newTower.HumanoidRootPart.Position).Magnitude
if distance < maxDistance then
print(target.Name, "is nearest target found so far")
nearestTarget = target
maxDistance = distance
end
end
return nearestTarget
end
function tower.Attack(newTower)
local target = FindNeartestTarget(newTower)
if target and target:FindFirstChild("Humanoid") and target.Humanoid.Health > 0 then
newTower.HumanoidRootPart.CFrame = CFrame.lookAt(newTower.HumanoidRootPart.Position, target.Position) -- Actually LOOK at the target
newTower.Humanoid:MoveTo(newTower.HumanoidRootPart.Position)
animateTowerEvent:FireAllClients(newTower, "Attack")
target.Humanoid:TakeDamage(25)
end
task.wait(1)
tower.Attack(newTower)
end
function tower.Spawn(player, name, cframe)
local towerExists = ReplicatedStorage.Towers:FindFirstChild(name)
if towerExists then
local newTower = towerExists:Clone()
newTower.HumanoidRootPart.CFrame = cframe
newTower.Parent = workspace.Towers
for i, object in ipairs(newTower:GetDescendants()) do
if object:IsA("BasePart") then
object.CollisionGroup = "Towers"
end
end
coroutine.wrap(tower.Attack)(newTower)
else
warn("Requested tower does not exist")
end
end
spawnTowerEvent.OnServerEvent:Connect(tower.Spawn)
return tower
local SererStorage = game:GetService("ServerStorage")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local events = ReplicatedStorage:WaitForChild("Events")
local spawnTowerEvent = events:WaitForChild("SpawnTower")
local animateTowerEvent = events:WaitForChild("AnimateTower")
local tower = {}
local function FindNeartestTarget(newTower)
local maxDistance = 25
local nearestTarget = nil
for i, target in ipairs(workspace.Mobs:GetChildren()) do
local distance = (target.HumanoidRootPart.Position - newTower.HumanoidRootPart.Position).Magnitude
if distance < maxDistance then
print(target.Name, "is nearest target found so far")
nearestTarget = target
maxDistance = distance
end
end
return nearestTarget
end
function tower.Attack(newTower)
local target = FindNeartestTarget(newTower)
if target and target:FindFirstChild("Humanoid") and target.Humanoid.Health > 0 then
newTower.HumanoidRootPart.CFrame = CFrame.lookAt(newTower.HumanoidRootPart.Position, target.HumanoidRootPart.Position) -- Actually LOOK at the target
newTower.Humanoid:MoveTo(newTower.HumanoidRootPart.Position)
animateTowerEvent:FireAllClients(newTower, "Attack")
target.Humanoid:TakeDamage(25)
end
task.wait(1)
tower.Attack(newTower)
end
function tower.Spawn(player, name, cframe)
local towerExists = ReplicatedStorage.Towers:FindFirstChild(name)
if towerExists then
local newTower = towerExists:Clone()
newTower.HumanoidRootPart.CFrame = cframe
newTower.Parent = workspace.Towers
for i, object in ipairs(newTower:GetDescendants()) do
if object:IsA("BasePart") then
object.CollisionGroup = "Towers"
end
end
coroutine.wrap(tower.Attack)(newTower)
else
warn("Requested tower does not exist")
end
end
spawnTowerEvent.OnServerEvent:Connect(tower.Spawn)
return tower
Tell me if this works, I’m not exactly sure how my brain is so smol sometimes