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

How do i create Global parts with local scripts?

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

This localscript creates a local part:

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

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

3 comments

1

Use RemoteEvents

0

Use a ServerScript, why would you use a Local one?

0

I was creating a building script which uses a GUI to select parts and things like that

1 answer

✓ Accepted answer

you can use RemoteEvents with arguments for check, example:

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

event.OnServerEvent:Connect(function(player,arg) -- the first parameter is player, second parameter is argument.
	if arg == "CreatePart" then -- If argument equal to CreatePart
		-- Create part script
		local part = Instance.new("Part")
		part.Parent = workspace
	end
end)

-- Client
local event = game.ReplicatedStorage.RemoteEvent -- RemoteEvent location

event: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:

local event = game.ReplicatedStorage.RemoteEvent -- RemoteEvent location

event.OnServerEvent:Connect(function(player,argument)
	if argument == "CreatePart" then
		local part = Instance.new("Part")
		part.Parent = workspace
	end
end)

Now on your LocalScript put this:

local event = game.ReplicatedStorage.RemoteEvent -- RemoteEvent location

-- Your functions...
event:FireServer("CreatePart")

Hope it helped

Wiki pages

Remote Events/Functions

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