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)
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
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.
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
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)