Егор Круглов
Ученик
(126),
на голосовании
4 месяца назад
Ошибка: Network Ownership API cannot be called on Anchored parts or parts welded to Anchored parts. - Server - Tower:55 Исправьте скрипт пж! Скрипт: local PhysicsService = game:GetService("PhysicsService") local ServerStorage = 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 = {}
function FindNearestTarget(newTower) local maxDistance = 15 local nearestTarget = nil
for i, target in ipairs(workspace.Mobs:GetChildren()) do local distance = (target.HumanoidRootPart.Position - newTower.HumanoidRootPart.Position).Magnitude print( target.Name , distance) if distance < maxDistance then print( target.Name , "is the nearest target found so far") nearestTarget = target maxDistance = distance end end
return nearestTarget end
function tower.Attack(newTower) local target = FindNearestTarget(newTower)
Исправьте скрипт пж!
Скрипт:
local PhysicsService = game:GetService("PhysicsService")
local ServerStorage = 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 = {}
function FindNearestTarget(newTower)
local maxDistance = 15
local nearestTarget = nil
for i, target in ipairs(workspace.Mobs:GetChildren()) do
local distance = (target.HumanoidRootPart.Position - newTower.HumanoidRootPart.Position).Magnitude
print( target.Name , distance)
if distance < maxDistance then
print( target.Name , "is the nearest target found so far")
nearestTarget = target
maxDistance = distance
end
end
return nearestTarget
end
function tower.Attack(newTower)
local target = FindNearestTarget(newTower)
if target and target:FindFirstChild("Humanoid") and target.Humanoid.Health > 0 then
local targetCFrame = CFrame.lookAt(newTower.HumanoidRootPart.Position, target.HumanoidRootPart.Position)
newTower.HumanoidRootPart.BodyGyro.CFrame = targetCFrame
target.Humanoid:TakeDamage(25)
end
task.wait(1)
animateTowerEvent:FireAllClients(newTower, "Attack")
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
newTower.HumanoidRootPart:SetNetworkOwner(nil)
local bodyGyro = Instance.new ("BodyGyro")
bodyGyro.MaxTorque = Vector3.new (math.huge, math.huge, math.huge)
bodyGyro.D = 0
bodyGyro.CFrame = newTower.HumanoidRootPart.CFrame
bodyGyro.Parent = newTower.HumanoidRootPart
for i, object in ipairs(newTower:GetDescendants()) do
if object:IsA("BasePart") then
object.CollisionGroup = "Tower"
end
end
coroutine.wrap(tower.Attack)(newTower)
else
warn("Requested tower does not exist", name)
end
end
spawnTowerEvent.OnServerEvent:Connect(tower.Spawn)
return tower