Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make this placement system work with multiplayer?

Hey, So I followed this tutorial online for this simple placement system but the problem that the parts you place are only local. How do i get it so when you place a part everyone can see it?

This is the localscript:

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

local Part = workspace.Movement.PrimaryPart

Mouse.Move:Connect(function()
	local posX = Mouse.Hit.X
	local posY = 0
	local posZ = Mouse.Hit.Z
	
	
	Part.Parent:MoveTo(Vector3.new(posX, posY, posZ))
end)


Mouse.Button1Down:Connect(function()
	local ClonedPart = Part.Parent:Clone()
	ClonedPart.Parent = workspace.Clones
	ClonedPart.PrimaryPart.Position = Part.Position 
end)

3 comments

0

I'm working on an answer right now. Hold on for 1-2 mins.

0

Sure, thanks for trying to help me.

0

Use RemoteEvents to create part

1 answer

✓ Accepted answer

You need to use RemoteEvents to create part, example:

-- Client
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Event = game.ReplicatedStorage.RemoteEvent -- RemoteEvent location

Mouse.Button1Down:Connect(function()
    Event:FireServer("CreatePart") -- Fire server with argument "CreatePart"
end)

-- Server
local Event = game.ReplicatedStorage.RemoteEvent -- RemoteEvent location

Event.OnServerEvent:Connect(function(player,arg) -- The first parameter is player, second parameter is argument send by client
	if arg == "CreatePart" then -- Check if argument is equal to CreatePart
		-- Clone part to Workspace
		local Part = game.ReplicatedStorage.Part:Clone()
		Part.Name = "ClonedPart"
		Part.Parent = workspace
	end
end)

Also for your script do not put the "Movement" in workspace, put in ReplicatedStorage.

Now create a RemoteEvent in ReplicatedStorage, and create a Script in ServerScriptService And put this code:

-- ServerScript(Script)
local Event = game.ReplicatedStorage.RemoteEvent

Event.OnServerEvent:Connect(function(player,arg,position)
	if arg == "CreatePart" then
		local ClonedPart = game.ReplicatedStorage.Movement:Clone() -- Location of Movement with :Clone()
	    ClonedPart.Parent = workspace.Clones
	    ClonedPart.PrimaryPart.Position = position
	end
end)

Now on your LocalScript put this code:

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

local Event = game.ReplicatedStorage.RemoteEvent -- Event location
-- Put the Movement in ReplicatedStorage
local ClonedPart = game.ReplicatedStorage.Movement:Clone() -- Clone the Movement
ClonedPart.Parent = workspace -- Set parent to workspace
local Part = ClonedPart.PrimaryPart -- PrimaryPart of model
local position -- Do not change

Mouse.Move:Connect(function()
	local posX = Mouse.Hit.X
	local posY = 0
	local posZ = Mouse.Hit.Z
	
	position = Vector3.new(posX,posY,posZ) -- Set position to variable "position"
	Part.Parent:MoveTo(position)
end)


Mouse.Button1Down:Connect(function()
    Event:FireServer("CreatePart",position) -- Fire server with argument "CreatePart" and PartPosition
end)

Hope it helped :)

Wiki pages

RemoteEvents/Functions

This discussion is preserved as it was. New answers, comments, and votes are closed.