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

[CLOSED] How can I make a !createpart (number of parts) command?

Is it possible to make a command so you can say !createparts 50 then it will make 50 parts in the workspace? I'm unsure where to start, any code examples would be helpful!

I already have the main chatted event set up, I'm just unsure about the creating the amount of parts the player says

game.Players.PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(msg)
		if msg[1] == "!createparts" then
			local partsToMake = tonumber(msg[2]) 
			
			print(partsToMake)

		end
	end)
end)

11 comments

0

Instance.new()

0

I already know that aswell, I'm talking about the actual number of parts to make

0

make a function and an argument for number of parts

0

I need an example of how you would make the specified parts the player said

0

specify your question we're not sure what you want, also try to create your own code and post it here because this is not a request site

0

i did, you didnt read what i put correctly

0

right, i got confused with your comment so i thought you wanted something else, that was my bad, sorry

0

i'm gonna try to do something that might help you

0

okay, i appreciate your help

0

I'm going to post my code of what I have

0

Okay updated, just saying the code doesnt seem to print anything

4 answers

✓ Accepted answer

so i meant you can do something like this

local function createPart(number)
	
	for i = 1, number do
		
		local part = Instance.new("Part")
		part.Parent = game.Workspace
		wait(1)
		
	end
	
end

then store the number the player said in a variable and call the function with that variable, maybe like this:

local num = string.match(message, '%d+') --%d+ is used to match digits

createPart(num)

and yeah

5 comments

0

I'll try it now

0

Doesn't seem to work, heres the code

0

local function createPart(number) for i = 1, number do local part = Instance.new("Part") part.Parent = game.Workspace part.Name = "Bobbb" wait(1) end end game.Players.PlayerAdded:Connect(function(plr) plr.Chatted:Connect(function(msg) if msg == "!createparts" then local num = string.match(msg, '%d+') --%d+ is used to match digits print(num) createPart(n

0

try this: if msg == "!createparts" .. "%d+" maybe that will work

0

instead of if msg == "!createparts" and also you didnt close function properly put end) instead of end

What you are looking for is Player.Chatted event. It fires when a player chats. You can learn more here. In addition, you can look up on youtube such as this.

5 comments

0

I know that bit, I mean the actual creating the parts.

0

If you follow the youtube video I have sent, the commands has already been setup. All you need to do is modify the code a bit to listen for 'createparts".

0

I already said I know how to make the chatting event, I'm stuck on the creating the specified parts

0

Wdym 'specified parts'?

0

yeah i was confused about that too, he means "specified number of parts"

Try this

player = game.Players.LocalPlayer

player.Chatted:Connect(function(msg)
	if string.sub(msg,1,11) == "!createparts" then
		value = string.sub(msg,12)
		for i = 1,value,1 do
			newPart = Instance.new("Part")
			newPart.Parent = workspace
		end
	end
end

2 comments

0

lol, do u know that u can only use game.Players.LocalPlayer in a local script?

0

i am using local example, but i recommend player added stuff

Use Script and put into ServerScriptService This will work 100% bc i test it.

game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(message)
		if message:sub(1,13) == "!createparts " then
		local number = (message:sub(14))
			if number then
				for i = 1,number,1 do
				local part = Instance.new("Part",workspace)
				part.Name = "Parts"
				part.Position = Vector3.new(math.random(-148,148),2.5,math.random(-148,148)) --this is random position of part, if u don't want random then remove 'math.random(-148,148),2.5,math.random(-148,148)' and make position by your choice
				part.Size = Vector3.new(4,4,4) 
				print(part.Name.." Created") -- remove this line if u don't want to print
				end
			end
		end
	end)
end)

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