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

How do i create Global parts with local scripts?

Asked by 6 years ago

The question is really simple, Is there any way to create a global part with a local script?

This localscript creates a local part:

1local part = Instance.new("Part")
2part.Parent = workspace

But how do i make it so that the script instead creates a global part?

1
Use RemoteEvents yHasteeD 1819 — 6y
0
Use a ServerScript, why would you use a Local one? HeyItzDanniee 252 — 6y
0
I was creating a building script which uses a GUI to select parts and things like that Vinceberget 1420 — 6y

1 answer

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

you can use RemoteEvents with arguments for check, example:

01-- Server
02local event = game.ReplicatedStorage.RemoteEvent -- RemoteEvent location
03 
04event.OnServerEvent:Connect(function(player,arg) -- the first parameter is player, second parameter is argument.
05    if arg == "CreatePart" then -- If argument equal to CreatePart
06        -- Create part script
07        local part = Instance.new("Part")
08        part.Parent = workspace
09    end
10end)

1-- Client
2local event = game.ReplicatedStorage.RemoteEvent -- RemoteEvent location
3 
4event:FireServer("CreatePart") -- here you dont need to send player, only argument. i send argument "CreatePart"

For your script use this:

Create a RemoteEvent in ReplicatedStorage, now Create a Script(ServerScript/Regular Script) in ServerScriptService and put this code:

1local event = game.ReplicatedStorage.RemoteEvent -- RemoteEvent location
2 
3event.OnServerEvent:Connect(function(player,argument)
4    if argument == "CreatePart" then
5        local part = Instance.new("Part")
6        part.Parent = workspace
7    end
8end)

Now on your LocalScript put this:

1local event = game.ReplicatedStorage.RemoteEvent -- RemoteEvent location
2 
3-- Your functions...
4event:FireServer("CreatePart")

Hope it helped

Wiki pages

Remote Events/Functions

Ad

Answer this question