I made a script that will destroy blocks when clicked on them I made it in a local script and it only affects the client then I made a bindable event to make it affect the server
Here is the LocalScript
-- Get Player
local Player = game.Players.LocalPlayer
-- MainThings
local PlayerBuild = workspace.Build1.Build
local TileGrid = workspace.Build1.Tiles
local Mouse = Player:GetMouse()
local TargetedBlock
-- Border
local Border = Instance.new("SelectionBox")
Border.Parent = workspace
Border.LineThickness = .01
Border.Color3 = Color3.new(255,255,255)
-- Services
local RunService = game:GetService("RunService")
-- Block Data Handler
local BlockSize = Vector3.new(3,3,3)
local BlockMaterial = Enum.Material.Wood
local BlockColor = BrickColor.White()
-- Events
local PlaceBlock = game.ReplicatedStorage.PlaceBlock
local RemoveBlock = game.ReplicatedStorage.RemoveBlock
-- Make Border on Targeted Block
RunService.Heartbeat:Connect(function()
local Target = Mouse.Target
if Target then
if Target.Parent == TileGrid or PlayerBuild then
Border.Adornee = Target
TargetedBlock = Target
else
Border.Adornee = nil
TargetedBlock = nil
end
end
end)
-- Create Block on Click
Mouse.Button1Down:Connect(function()
if TargetedBlock then
-- Up
if Mouse.TargetSurface == Enum.NormalId.Top then
PlaceBlock:FireServer(BlockMaterial, BlockColor, (TargetedBlock.Position + Vector3.new(0,3,0)))
print("Attempt to place block")
end
-- Down
if Mouse.TargetSurface == Enum.NormalId.Bottom then
PlaceBlock:FireServer(BlockMaterial, BlockColor, (TargetedBlock.Position + Vector3.new(0,-3,0)))
print("Attempt to place block")
end
-- Left
if Mouse.TargetSurface == Enum.NormalId.Left then
PlaceBlock:FireServer(BlockMaterial, BlockColor, (TargetedBlock.Position + Vector3.new(-3,0,0)))
print("Attempt to place block")
end
-- Right
if Mouse.TargetSurface == Enum.NormalId.Right then
PlaceBlock:FireServer(BlockMaterial, BlockColor, (TargetedBlock.Position + Vector3.new(3,0,0)))
print("Attempt to place block")
end
-- Front
if Mouse.TargetSurface == Enum.NormalId.Front then
PlaceBlock:FireServer(BlockMaterial, BlockColor, (TargetedBlock.Position + Vector3.new(0,0,-3)))
print("Attempt to place block")
end
-- Back
if Mouse.TargetSurface == Enum.NormalId.Back then
PlaceBlock:FireServer(BlockMaterial, BlockColor, (TargetedBlock.Position + Vector3.new(0,3,3)))
print("Attempt to place block")
end
end
end)
-- Remove Block
Mouse.Button2Down:Connect(function()
if TargetedBlock.Parent == PlayerBuild then
print("Attempt to remove block")
RemoveBlock:FireServer(TargetedBlock)
end
end)
The RemoveBlock part is in Line 80
Here is that part
-- Remove Block
Mouse.Button2Down:Connect(function()
if TargetedBlock.Parent == PlayerBuild then
print("Attempt to remove block")
RemoveBlock:FireServer(TargetedBlock)
end
end)
And here is the Event script
local Events = game.ReplicatedStorage
-- Place Block
Events.PlaceBlock.OnServerEvent:Connect(function(player, Mat, Color, Position)
print("Block Is Placed!")
local NewBlock = Instance.new("Part")
NewBlock.BrickColor = Color
NewBlock.Material = Mat
NewBlock.Size = Vector3.new(3,3,3)
NewBlock.Position = Position
NewBlock.Parent = workspace.Build1.Build
NewBlock.Anchored = true
NewBlock.Name = "Block"
end)
-- Remove Block
Events.RemoveBlock.OnServerEvent:Connect(function(Block)
print("Block is removed")
Block:Destroy()
end)
When I test it deletes the character for some reason, please help to fix this

1 comment
You can't use a BindableEvent for this. What you want is a RemoteEvent. https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events