task.wait(1)
local Placing = false
local GhostTower
local UIS = game:GetService(“UserInputService”)
local GhostMovementfunction ShowPlaceable_Area(on)
if on == true then
for i, v in ipairs(game.Workspace.PlaceableArea:GetChildren()) do
if v:IsA(“BasePart”) then
v.Transparency = 0.7
end
end
else
for i, v in ipairs(game.Workspace.PlaceableArea:GetChildren()) do
if v:IsA(“BasePart”) then
v.Transparency = 1
end
end
end
endUIS.InputBegan:Connect(function(input, gameProcessedEvent)
if gameProcessedEvent then
return
endif input.UserInputType == Enum.UserInputType.MouseButton1 then
local mouse = game.Players.LocalPlayer:GetMouse()
if mouse.Target then
if mouse.Target.Parent.Name == “PlaceableArea” then
if Placing == true then
Placing = falseif GhostTower then GhostTower:Destroy() print("placingTower on: " .. tostring(mouse.Target)) if GhostMovement then GhostMovement:Disconnect() end ShowPlaceable_Area(false) end end end endend
end)for i, v in ipairs(script.Parent:GetDescendants()) do
if v:IsA(“ImageButton”) then
v.MouseButton1Click:Connect(function()
if Placing == false then
Placing = true
if v.Parent:FindFirstChild(“Tower”) then
GhostTower = game.ReplicatedStorage.Towers:FindFirstChild(v.Parent.Tower.Value):Clone()
GhostTower.Parent = game.Workspace
local mouse = game.Players.LocalPlayer:GetMouse()
GhostMovement = game:GetService(“RunService”).RenderStepped:Connect(function()
if GhostTower then
if mouse.Target then
GhostTower:PivotTo(
CFrame.new(mouse.Hit.Position) *
CFrame.new(0, GhostTower.PrimaryPart.Size.Y * 1.2, 0)
)
end
end
end)ShowPlaceable_Area(true) end else Placing = false if GhostTower then GhostTower:Destroy() end if GhostMovement then GhostMovement:Disconnect() end ShowPlaceable_Area(false) end end)end
end
The code pasted pretty weirdly but it is all connected.
Anyway, im making a tower placement system but i have only just started on the client side. when you click a button, it makes you drag a ghost tower( like in most td games ) until you click. but the cursor is hitting the ghost tower. once i get help with that there will probably be another problem. so the placeable area are basicly parts that you can place towers on. That is detected with mouse.Target but the ghost tower would be in the way