I’m making a grid placing system, which works perfectly. I have a GUI where you can select which block you want to place, each button has a value in it that points to which block is assigned to that button.
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local RS = game:GetService("ReplicatedStorage")
local function PlaceBlock(Block)
print("Started")
if #workspace.GhostBlock:GetChildren() == 1 then
workspace.GhostBlock:GetChildren()[1]:Destroy()
end
--print(Block)
Block.Anchored = true
Block.Orientation = Vector3.new(0,0,0)
local BlockGhost = Block:Clone()
BlockGhost.Parent = workspace.GhostBlock
BlockGhost.Transparency = 0.5
BlockGhost.CanCollide = false
Mouse.TargetFilter = BlockGhost
local increment = 4
Mouse.Move:Connect(function()
local MousePos = Mouse.Hit.Position
local BlockPos = Vector3.new(0, Block.Size.Y / 2, 0)
BlockPos += Vector3.new(MousePos.X - Block.Size.X / 2, MousePos.Y, MousePos.Z - Block.Size.Z / 2)
local XPos = (Block.Size.X / 2) + math.round(BlockPos.X / increment) * increment
local YPos = math.round(BlockPos.Y)
local ZPos = (Block.Size.Z / 2) + math.round(BlockPos.Z / increment) * increment
BlockPos = Vector3.new(XPos, YPos, ZPos)
BlockGhost.Position = BlockPos
local parts = workspace:GetPartsInPart(BlockGhost)
if #parts >= 1 then
for i, v in pairs(parts) do
task.spawn(function()
if v:IsA("BasePart") then
BlockGhost.Color = Color3.fromRGB(255,0,0)
end
end)
end
else
BlockGhost.Color = Color3.fromRGB(0,255,0)
end
end)
Mouse.Button1Down:Connect(function()
print("Mouse down")
local pos = BlockGhost.Position
--print(Block.Name.." sent")
RS.Events.PlaceBlock:FireServer(Block, pos)
end)
end
local main = script.Parent
main.one.MouseButton1Click:Connect(function()
local block = main.one.Value.Value
PlaceBlock(block)
end)
main.two.MouseButton1Click:Connect(function()
local block = main.two.Value.Value
PlaceBlock(block)
end)
main.three.MouseButton1Click:Connect(function()
local block = main.three.Value.Value
PlaceBlock(block)
end)
However, it says ‘Mouse down’ 3 times when i select a second block, and also places 2 blocks, while when I ask it to print, it only says one block, and that block is the right one. What could be this issue?