Need help with voxel building script

so what i want to achieve is a server sided building system
but the issue is that it keeps giving errors like


i am lazy to look on devforums.

heres the script:

game:GetService("ReplicatedStorage").Placed.OnServerEvent:Connect(function(Position, Size, Weld0, Weld1)
	local Block = game:GetService("ServerScriptService"):WaitForChild("Block"):Clone()
	Block.Parent = game:GetService("Workspace")
	Block.Position = Position
	Block.Size = Size

	local Weld = Instance.new("Weld")
	Weld.Parent = Block
	Weld.Part0 = Weld0
	Weld.Part1 = Weld1
	
	Block.Anchored = false
end)

game:GetService("ReplicatedStorage").Destroyed.OnServerEvent:Connect(function(Block)
	Block.Parent = nil
end)

The first Argument in OnServerEvent is always the player that fired the event

game:GetService("ReplicatedStorage").Placed.OnServerEvent:Connect(function(Caller, Position, Size, Weld0, Weld1)
	local Block = game:GetService("ServerScriptService"):WaitForChild("Block"):Clone()
	Block.Parent = game:GetService("Workspace")
	Block.Position = Position
	Block.Size = Size

	local Weld = Instance.new("Weld")
	Weld.Parent = Block
	Weld.Part0 = Weld0
	Weld.Part1 = Weld1

	Block.Anchored = false
end)

game:GetService("ReplicatedStorage").Destroyed.OnServerEvent:Connect(function(Caller, Block)
	Block.Parent = nil
end)
1 Like

Don’t wanna forget to point that the Destroyed remote is extremely vulnerable.
I highly recommend OP parent Block inside a folder called Blocks within’ workspace.

Then you can somewhat limit the destroy remote.

Within’ Placed
Block.Parent = workspace.Blocks

then within’ Destroyed.

if Block:IsDescendantOf(workspace.Blocks) then
You could also do a magnitude check to limit the distance aswell.

i am not that expert at programming but its kinda helpful.

Thanks! might use this solution for future projects