I’m Working On A TD Game And Finishing The Building System And This Bug Popped Up Been Trying To Fix It All Day But With No Luck, I Would Love Help.
local Player = game.Players.LocalPlayer
local Gui = Player:WaitForChild("PlayerGui")
local TowerFolder = game.ReplicatedStorage.Towers
local Mouse = Player:GetMouse()
local ReplacteToSERVER = game.ReplicatedStorage.Events.LoadMap
local TowerChild = TowerFolder.Tower:GetChildren()
local isSpawning = false
local PlaceableLocation = false
local CurrentDecoy = nil
local GridSize = 3
--- Pos
local posX
local posY
local posZ
function SpawnDecoy()
local Tower = TowerFolder.Tower:Clone()
Tower.Parent = workspace.Towers.Decoys
for i, model in pairs(Tower:GetChildren()) do
if model:IsA('Part') then
model.Transparency = 0.5
model.CanCollide = false
end
end
Tower:MoveTo(Mouse.Hit.Position + Vector3.new(0,2.614,0))
return Tower
end
function Place()
local Owner = Instance.new("ObjectValue")
local FindNewTower = game.ReplicatedStorage.Towers:WaitForChild(CurrentDecoy.Name)
local NewTower = FindNewTower:Clone()
for i, model in pairs(NewTower:GetChildren()) do
if model:IsA('Part') then
if model.Name == "Hitbox" then
else
model.Transparency = 0
model.CanCollide = true
end
end
end
NewTower.Parent = workspace.Towers
NewTower:MoveTo(CurrentDecoy.PrimaryPart.Position)
Owner.Value = Player.Character
Owner.Name = "Owner"
Owner.Parent = NewTower
end
Gui.Build.BuildButton.Activated:Connect(function()
if (isSpawning == false) then
isSpawning = true
CurrentDecoy = SpawnDecoy()
Mouse.TargetFilter = CurrentDecoy
end
end)
function Snap()
posX = math.floor(Mouse.Hit.X / GridSize + 0) * GridSize
posY = Mouse.Hit.Y
posZ = math.floor(Mouse.Hit.Z / GridSize + 0) * GridSize
end
Mouse.Move:Connect(function()
if (isSpawning == false) or (CurrentDecoy == nil) then return end
-- Move Tower
Snap()
CurrentDecoy:MoveTo(Mouse.Hit.Position + Vector3.new(0,2.614,0))
-- Checks If Can Build
if (PlaceableLocation == true) then
if (Mouse.Target.Name ~= "PlaceTowers") then
PlaceableLocation = false
CurrentDecoy.Hitbox.BrickColor = BrickColor.Red()
end
else
if (Mouse.Target.Name == "PlaceTowers") then
PlaceableLocation = true
CurrentDecoy.Hitbox.BrickColor = BrickColor.Green()
end
end
end)
Mouse.Button1Down:Connect(function()
if (isSpawning == false) or (CurrentDecoy == nil) or (PlaceableLocation == false) then return end
Place()
end)
The Placing Func
function Place()
local Owner = Instance.new("ObjectValue")
local FindNewTower = game.ReplicatedStorage.Towers:WaitForChild(CurrentDecoy.Name)
local NewTower = FindNewTower:Clone()
for i, model in pairs(NewTower:GetChildren()) do
if model:IsA('Part') then
if model.Name == "Hitbox" then
else
model.Transparency = 0
model.CanCollide = true
end
end
end
NewTower.Parent = workspace.Towers
NewTower:MoveTo(Mouse.Hit.Position + Vector3.new(0,2.614,0))
Owner.Value = Player.Character
Owner.Name = "Owner"
Owner.Parent = NewTower
end
What The Bug Looks Like:
Video As A .WMV Download:
robloxapp-20210906-2224162.wmv (2.6 MB)
This Help Me!!! Again THANK YOU!