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

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

Asked by 4 years ago
Edited 4 years ago

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)
0
Instance.new() Lazarix9 245 — 4y
0
I already know that aswell, I'm talking about the actual number of parts to make Itzlewis99 26 — 4y
0
make a function and an argument for number of parts Lazarix9 245 — 4y
0
I need an example of how you would make the specified parts the player said Itzlewis99 26 — 4y
View all comments (7 more)
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 Lazarix9 245 — 4y
0
i did, you didnt read what i put correctly Itzlewis99 26 — 4y
0
right, i got confused with your comment so i thought you wanted something else, that was my bad, sorry Lazarix9 245 — 4y
0
i'm gonna try to do something that might help you Lazarix9 245 — 4y
0
okay, i appreciate your help Itzlewis99 26 — 4y
0
I'm going to post my code of what I have Itzlewis99 26 — 4y
0
Okay updated, just saying the code doesnt seem to print anything Itzlewis99 26 — 4y

4 answers

Log in to vote
0
Answered by
Lazarix9 245 Moderation Voter
4 years ago

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

0
I'll try it now Itzlewis99 26 — 4y
0
Doesn't seem to work, heres the code Itzlewis99 26 — 4y
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 Itzlewis99 26 — 4y
0
try this: if msg == "!createparts" .. "%d+" maybe that will work Lazarix9 245 — 4y
0
instead of if msg == "!createparts" and also you didnt close function properly put end) instead of end Lazarix9 245 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

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.

0
I know that bit, I mean the actual creating the parts. Itzlewis99 26 — 4y
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". XviperIink 428 — 4y
0
I already said I know how to make the chatting event, I'm stuck on the creating the specified parts Itzlewis99 26 — 4y
0
Wdym 'specified parts'? XviperIink 428 — 4y
0
yeah i was confused about that too, he means "specified number of parts" Lazarix9 245 — 4y
Log in to vote
0
Answered by 4 years ago

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
0
lol, do u know that u can only use game.Players.LocalPlayer in a local script? Itzlewis99 26 — 4y
0
i am using local example, but i recommend player added stuff megamanyoutuber 25 — 4y
Log in to vote
0
Answered by
G2001H 75
4 years ago

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)

Answer this question