local plr = game.Players.LocalPlayer
local UI = script.Parent.Parent.Parent.Parent
local grassbutton = script.Parent
local grassblock = game.ReplicatedStorage.Parts.GrassBlock
local active = false
grassbutton.MouseButton1Click:Connect(function()
active = true
local mouse = plr:GetMouse()
local firstclone = grassblock:Clone()
firstclone.Name = "TransparentBlock"
firstclone.Transparency = 0.6
firstclone.Position = Vector3.new(mouse.Hit.X, mouse.Hit.Y + 2, mouse.Hit.Z)
firstclone.Parent = workspace.Cursor
firstclone.CanCollide = false
local clone
mouse.Move:Connect(function()
if active then
if firstclone then
firstclone:Destroy()
end
if clone then
clone:Destroy()
end
mouse = plr:GetMouse()
clone = grassblock:Clone()
clone.Name = "TransparentBlock"
clone.Transparency = 0.6
clone.Position = Vector3.new(mouse.Hit.X, mouse.Hit.Y + 2, mouse.Hit.Z)
clone.Parent = workspace.Cursor
clone.CanCollide = false
end
end)
mouse.Button1Down:Connect(function()
if active then
active = false
local children = workspace.Cursor:GetChildren()
for i = 1, #children do
print(i, children[i].Name)
children[i]:Destroy()
end
local newclone = grassblock:Clone()
newclone.Name = "GrassBlock"
newclone.Position = Vector3.new(mouse.Hit.X, mouse.Hit.Y + 2, mouse.Hit.Z)
newclone.Parent = workspace
newclone.CanCollide = false
print("Placed new " .. newclone.Name .. " at (" .. newclone.Position.X .. ", " .. newclone.Position.Y .. ", " .. newclone.Position.Z .. ")")
end
end)
end)
Everytime I place a block, a new clone is added (NOT WHAT IT’S SUPPOSED TO DO)
I placed 4 blocks in the image shown, and it started creating 4 cursors/hover blocks instead of only 1
Any idea how to fix?
THANKS IF YOU DO HELP!