You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve?
Im making a tower defense game which is coming on really well. -
What is the issue?
A couple of my towers fly around the room about 20ish seconds after placing them. Its like they start pivoting and then spin around the room hitting walls, ceilings, floors lol. Im afraid that this may occur with further towers that i create. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Ive changed the hip height lots of times. Ive also change the lookVector to x,z position and turned y off. Ive tried turnignx off too. Ive also changed the size of the HumanoidRootPart. What have i missed? My code is below. I appreciate any help, guidance, etc, my code is below.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
-- This is an example Lua code block
function FindNearestTarget(newTower, range)
local nearestTarget = nil
for i, target in ipairs(workspace.Zombies:GetChildren()) do
local distance = (target.HumanoidRootPart.Position - newTower.HumanoidRootPart.Position).Magnitude
if distance < range then
nearestTarget = target
range = distance
end
end
return nearestTarget
end
function tower.FindTarget(newTower, range)
end
function tower.Attack(newTower, player)
local config = newTower.Config
local target = FindNearestTarget(newTower, config.Range.Value)
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
newTower.HumanoidRootPart.BodyGyro.CFrame = CFrame.new(Vector3.new(0,0,0), targetCFrame.LookVector * Vector3.new(1,0,1))
animateTowerEvent:FireAllClients(newTower, "Attack", target)
target.Humanoid:TakeDamage(config.Damage.Value)
if target.Humanoid.Health <= 0 then
player.Zzzs.Value += 25
end
task.wait(config.Cooldown.Value)
end
task.wait(0.1)
if newTower and newTower.Parent then
tower.Attack(newTower, player)
end
end
function tower.Sell(player, model)
if model and model:FindFirstChild("Config") then
if model.Config.Owner.Value == player.Name then
player.PlacedTowers.Value -= 1
player.Zzzs.Value += model.Config.Price.Value / 1.5
model:Destroy()
return true
end
end
warn("Unable to sell this tower")
return false
end
sellTowerFunction.OnServerInvoke = tower.Sell
function tower.Spawn(player, name, cframe, previous)
local allowedToSpawn = tower.CheckSpawn(player, name, previous)
if allowedToSpawn then
local newTower
if previous then
previous:Destroy()
newTower = ReplicatedStorage.Towers.Upgrades[name]:Clone()
else
newTower = ReplicatedStorage.Towers[name]:Clone()
player.PlacedTowers.Value += 1
end
local ownerValue = Instance.new("StringValue")
ownerValue.Name = "Owner"
ownerValue.Value = player.Name
ownerValue.Parent = newTower.Config
local targetMode = Instance.new("StringValue")
targetMode.Name = "TargetMode"
targetMode.Value = "First"
targetMode.Parent = newTower.Config
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
PhysicsService:SetPartCollisionGroup(object, "Towers")
end
end
player.Zzzs.Value -= newTower.Config.Price.Value
coroutine.wrap(tower.Attack)(newTower, player)
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.