Need help with making a script, where, if you place blocks, other players can see it

I’m very new to remote events, so I apologize in advance if the code looks horrendous.
I’ll just show the scripts:
Building script (this is inside a tool):

                                 ---------------------------------------------VARIBLES-------------------------------------------------
local runService = game:GetService("RunService")
local tool = script.Parent
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local grid = 1.5
local blueBlock = game.ReplicatedStorage:WaitForChild("BlueBlock")
local shadow_block = blueBlock:Clone(); shadow_block.Transparency = .5; shadow_block.Parent = workspace.Blocks.ShadowBlocks; shadow_block.CanCollide = false
if shadow_block.CanCollide == true then
	print("BRUH")
end

mouse.TargetFilter = shadow_block

                                ---------------------------------------------FUNCTIONS-------------------------------------------------

function snapToGrid(x)
	return math.floor(x/grid + 0.5)*grid
end

function calculateY(toP, toS, oS)
	return (toP + toS * 0.5) + oS * 0.5
end

runService.RenderStepped:Connect(function()
	if mouse.Target ~= nil then
		shadow_block.Position = Vector3.new(snapToGrid(mouse.Hit.Position.X), calculateY(mouse.Target.Position.Y, mouse.Target.Size.Y, blueBlock.Size.Y), snapToGrid(mouse.Hit.Position.Z))
	end
end)

mouse.Button1Down:Connect(function()
	if tool:FindFirstAncestorWhichIsA('Model') == player.Character then
		local clone = blueBlock:Clone()
		clone.Parent = workspace.Blocks.BlueBlocks
		clone.Position = shadow_block.Position
		print("script is working")
	end
end)
runService.RenderStepped:Connect(function()
	if tool:FindFirstAncestorWhichIsA("Model") ~= player.Character then
		shadow_block.Transparency = 1
	end
end)
runService.RenderStepped:Connect(function()
	if tool:FindFirstAncestorWhichIsA("Model") == player.Character then
		shadow_block.Transparency = 0.5
	end
end)

Server script inside ServerScriptService:

local remoteEvent = game.ReplicatedStorage:WaitForChild("BuildingSystemEvent")

remoteEvent.OnServerEvent:Connect(function(player, )
end)

The script i need help with making (this is in starter player scripts):



local remoteEvent = game.ReplicatedStorage:WaitForChild("BuildingSystemEvent")

local red_block = workspace.Blocks.RedBlocks:GetChildren()

local blue_block = workspace.Blocks.BlueBlocks:GetChildren()

remoteEvent:FireServer(function()

end)

PLEASE HELP

1 Like

Hello!
I have seen what you need and here is the basics on how to do it!
I hope you can figure the rest out!

So basically once the tool is activated

Tool.Activated:Connect(function()

we get a certain position and send it to the server.

remoteEvent:FireServer(Position)
You send what ever position you want! It can be mouse position or some other one

Next on the server you just make a part when the event is fired.

event.OnServerEvent:Connect(function(player, position)


then make the part as so:

local part = instance.new("Part")
part.Size = vector3.new(3,3,3)
part.Position = position
part.Anchored = true

and thats the basics on how you would make a part once they activate the tool.


also instead of using,

mouse.Button1Down

use:

tool.Activated.


This means it will run when they click on there screen. It also runs on mobile!


Also dont make the part on the client, only make it on the server. and if you wish to clone that certain item. Just send it to the server.

1 Like

But why would I need to make a part, when I already made my building system? Or do you want the part to be created in the ServerScript?

1 Like

You need to create the part in ServerScript ( If you want it to show on everyone ) because the LocalScript only affect the person that had the same LocalScript ( If you store it inside of StarterPlayerScripts or idk ).

1 Like

But what do I do with the originial building system script?

Aight, you will need to change the LocalScript to ServerScript but you will probably gonna use the old one still for making the shadow_block to show on the player and the snap one

1 Like

Then?

(character limit is annoying)

So do I just port the most of my script to the new local script that will send those varibles to the server?

No, your local script must be local, only you must pass the following arguments to the server: coordinates, part, and then when you receive this information and process it (check), you do the same as on the client (clone, change position and parent). (I recommend using CFrame and not Position)

--localscript
mouse.Button1Down:Connect(function()
	if tool:FindFirstAncestorWhichIsA('Model') == player.Character then
		remote:FireServer("blueBlock", shadow_block.Position)
	end
end)

--serverscript

remote.OnServerEvent:Connect(function(plr, block, position)
	--code to secure you remote...
	local clone = game.ReplicatedStorage:WaitForChild(block):Clone()
	clone.Parent = workspace.Blocks.BlueBlocks
	clone.Position = Vector3.new(position)
end)
2 Likes

I was about to write script on how to do that but well, guess I done here.

1 Like

I changed the script in the tool to this:

                                 ---------------------------------------------VARIBLES-------------------------------------------------
local remoteEvent = game.ReplicatedStorage:WaitForChild("BuildingSystemEvent")
local runService = game:GetService("RunService")
local tool = script.Parent
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local grid = 1.5
local blueBlock = game.ReplicatedStorage:WaitForChild("BlueBlock")
local shadow_block = blueBlock:Clone(); shadow_block.Transparency = .5; shadow_block.Parent = workspace.Blocks.ShadowBlocks; shadow_block.CanCollide = false
if shadow_block.CanCollide == true then
	print("BRUH")
end

mouse.TargetFilter = shadow_block

                                ---------------------------------------------FUNCTIONS-------------------------------------------------

function snapToGrid(x)
	return math.floor(x/grid + 0.5)*grid
end

function calculateY(toP, toS, oS)
	return (toP + toS * 0.5) + oS * 0.5
end

runService.RenderStepped:Connect(function()
	if mouse.Target ~= nil then
		shadow_block.Position = Vector3.new(snapToGrid(mouse.Hit.Position.X), calculateY(mouse.Target.Position.Y, mouse.Target.Size.Y, blueBlock.Size.Y), snapToGrid(mouse.Hit.Position.Z))
	end
end)

tool.Activated:Connect(function()
	if tool:FindFirstAncestorWhichIsA('Model') == player.Character then
		remoteEvent:FireServer("blueBlock", shadow_block.Position)
		print("script is working")
	end
end)
runService.RenderStepped:Connect(function()
	if tool:FindFirstAncestorWhichIsA("Model") ~= player.Character then
		shadow_block.Transparency = 1
	end
end)
runService.RenderStepped:Connect(function()
	if tool:FindFirstAncestorWhichIsA("Model") == player.Character then
		shadow_block.Transparency = 0.5
	end
end)

But when I start the game, and i try to place a block, the blueblock in replicatedstorage disappears. And then (obviously), it gives me a infinite yield, since it doesn’t exist anymore. PLEASE HELP

here’s the script in serverscriptservice:


local remoteEvent = game.ReplicatedStorage:WaitForChild("BuildingSystemEvent")

remoteEvent.OnServerEvent:Connect(function(player, block, position)
	local clone = game.ReplicatedStorage:WaitForChild("BlueBlock")
	clone.Parent = workspace.Blocks.BlueBlocks
	clone.Position = Vector3.new(position)
end)

Yes it should be created server side

I understand that, thank you, but there is an error, and i can’t fix it, could you please read the top 2 posts

1 Like

Are you sure you are using this?

remote.OnServerEvent:Connect(function(plr, block, position)
	--code to secure you remote...
	local clone = game.ReplicatedStorage:WaitForChild(block):Clone()
	clone.Parent = workspace.Blocks.BlueBlocks
	clone.Position = Vector3.new(position)
end)

In this case add Clone()

local clone = game.ReplicatedStorage:WaitForChild("BlueBlock"):Clone()

Ok, the error is gone, but the problem is, is that I still can’t place the block.

And it DOES appear in it’s parent, but it still doesn’t appear.

It doesn’t show up or what? Can you be more specific please, and if there are errors, please send them.

1 Like

It’s probably because you forgot to remove the shadow_block ( I don’t sure about this one )

1 Like