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

Creating a Part with a button?

I've been fondling and playing around with roblox Lua lately, and I decided to create a text button that, when pressed, creates a part.

however.... everything seems to be functioning but I don't see any parts being created.

There are two scripts.

a local script inside the button;

local players = game:GetService("Players")

local player = players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local Button = player.PlayerGui:WaitForChild("CreatePartButton")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local createPartEvent = ReplicatedStorage:WaitForChild("CreatePartEvent")

local function CreatePart()
	createPartEvent:FireServer(BrickColor.Green(), Vector3.new(0, 20 , 0))
end

Button.MouseButton1Click:Connect(CreatePart)

and a script in replicated storage;

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local createPartEvent = Instance.new("RemoteEvent", ReplicatedStorage)

createPartEvent.Name = "CreatePartEvent"

local function onCreatePartFired(player)
	print(player.Name, "wants to create a part")
	local newPart = Instance.new("Part")
	newPart.BrickColor = color
	newPart.Position = position
	newPart.Parent = game.Workspace
end

createPartEvent.OnServerEvent:connect(onCreatePartFired)

1 comment

0

You've been fondling and playing around?

2 answers

Scripts won't run in ServerStorage or ReplicatedStorage. Put the server Script in ServerScriptService or the Workspace.

What you're trying to do is really complicated for just creating a new part, I'm not sure how to have the script in a text button but what I know is that you can do this.

create a part in the workspace and insert a click detector and then a script into the click detector. in that script write:


script.Parent.MouseClick:connect(function()
	local newpart = Instance.new("Part", workspace)
	newpart.Position = Vector3.new(-178.67, 0.359, 116.497) -- wherever you want to place the new part
	newpart.Name = "Timothy" -- whatever you want to name it
	newpart.Transparency = 0 -- transparency you want
	newpart.Anchored = true
	newpart.Orientation = Vector3.new(0, 0, 0) -- if you want to rotate the part.
	newpart.BrickColor = BrickColor.new("Bright green")
end)


Again, I'm not sure how to put it in a text button but that's just an example of how you can create a new part with a click.

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