Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make this placement system work with multiplayer?

Asked by 5 years ago

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)
0
I'm working on an answer right now. Hold on for 1-2 mins. moo1210 587 — 5y
0
Sure, thanks for trying to help me. Alwaysrube 22 — 5y
0
Use RemoteEvents to create part yHasteeD 1819 — 5y

1 answer

Log in to vote
1
Answered by
yHasteeD 1819 Moderation Voter
5 years ago

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

Ad

Answer this question