I am working on a grid placement. The only thing that I am struggling with is the grid part. I tried making a grid script using a video but it doesn’t work. I keep getting errors say that the brick’s parent is locked. I am trying to make a building system like in the game “skywars”. Edit: I forgot that when I equip the tool, the block doesn’t show up
local player = game.Players.LocalPlayer
local mouse = game.Players.LocalPlayer:GetMouse()
local off = false
local posx
local posy
local posz
local gridsize = 4
local clonedbrick = game.ReplicatedStorage.Brick:Clone()
local function snap(brick)
posx = math.floor(mouse.Hit.X/gridsize + 0.5) * gridsize
posy = clonedbrick.Position.Y
posz = math.floor(mouse.Hit.Z/gridsize + 0.5) * gridsize
end
script.Parent.Equipped:Connect(function()
if mouse ~= nil then
mouse.TargetFilter = clonedbrick
snap()
clonedbrick.Transparency = .5
clonedbrick.Parent = workspace
while mouse ~= nil do
clonedbrick.Position = mouse.Hit.p + Vector3.new(posx,posy,posz)
wait()
if off then
clonedbrick:Destroy()
off = false
break
end
end
end
end)
script.Parent.Activated:Connect(function()
local BrickToPlace = game.ReplicatedStorage.Brick:Clone()
local pos = mouse.Hit.p + Vector3.new(posx,posy,posz)
if(pos - player.Character.HumanoidRootPart.Position).magnitude <= 12 then
script.Parent.RemoteEvent:FireServer(pos)
end
end)
script.Parent.Unequipped:Connect(function()
off = true
end)
Here’s the script I have made, but there are still problems like when I unequip the tool, the block doesn’t go away. Does anybody know how to fix this?
local player = game.Players.LocalPlayer
local mouse = game.Players.LocalPlayer:GetMouse()
local off = false
local posx
local posy
local posz
local gridsize = 4
local function snap(clonedbrick)
posx = math.floor(mouse.Hit.X/gridsize + 0.5) * gridsize
posy = math.floor(mouse.Hit.Y/gridsize + 0.5) * gridsize
posz = math.floor(mouse.Hit.Z/gridsize + 0.5) * gridsize
end
script.Parent.Equipped:Connect(function()
local clonedbrick = game.ReplicatedStorage.Brick:Clone()
mouse.TargetFilter = clonedbrick
mouse.Move:Connect(function()
snap()
clonedbrick.Transparency = .5
clonedbrick.Parent = workspace
while mouse ~= nil do
clonedbrick.CFrame = CFrame.new(posx,posy,posz)
wait()
if off == true then
clonedbrick.Parent = nil
off = false
break
end
end
end)
end)
script.Parent.Activated:Connect(function()
local BrickToPlace = game.ReplicatedStorage.Brick:Clone()
local pos = mouse.Hit.p + Vector3.new(posx,posy,posz)
if(pos - player.Character.HumanoidRootPart.Position).magnitude <= 12 then
script.Parent.RemoteEvent:FireServer(pos)
end
end)
script.Parent.Unequipped:Connect(function()
off = true
end)
local player = game.Players.LocalPlayer
local mouse = game.Players.LocalPlayer:GetMouse()
local off = false
local tool = script.Parent
local equipped = false
local posx
local posy
local posz
local gridsize = 4
local function snap(clonedbrick)
posx = math.floor(mouse.Hit.X/gridsize + 0.5) * gridsize
posy = math.floor(mouse.Hit.Y/gridsize + 0.5) * gridsize
posz = math.floor(mouse.Hit.Z/gridsize + 0.5) * gridsize
end
tool.Equipped:Connect(function()
if equipped == false then
equipped = true
local clonedbrick = game.ReplicatedStorage.Brick:Clone()
mouse.TargetFilter = clonedbrick
mouse.Move:Connect(function()
snap()
clonedbrick.Transparency = .5
clonedbrick.Parent = workspace
while mouse ~= nil do
clonedbrick.CFrame = CFrame.new(posx,posy,posz)
wait()
if off == true or equipped == false then
clonedbrick:Destroy()
off = false
break
end
end
end)
end
end)
script.Parent.Activated:Connect(function()
local BrickToPlace = game.ReplicatedStorage.Brick:Clone()
local pos = mouse.Hit.p + Vector3.new(posx,posy,posz)
if(pos - player.Character.HumanoidRootPart.Position).Magnitude <= 12 then
script.Parent.RemoteEvent:FireServer(pos)
end
end)
script.Parent.Unequipped:Connect(function()
if equipped == true then
equipped = false
off = true
end
end)
Maybe cause you are parenting the clonebrick as nil, so it wont change its parent. Try using that
Its cause the parent is being argumented when mouse is moving, so due to we say, when off is true or equipped is false, the parent is nil, cause the brick is destroyed, move out “clonebrick.Parent = workspace” of the mouse.Move function, and place it under the first argument of clonebrick, wich should be local clonebrick…