Q to create 2 builders script issue

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    A script that creates 2 builder bots when Q is pressed.
  2. What is the issue? Include screenshots / videos if possible!
    It doesn’t work, but theres no error.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Changing numbers, yes.
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
function Input(input)
	if input.KeyCode==Enum.KeyCode.Q then
		for i=1,3,1 do
			local bot=game:GetService("ServerStorage").Builder:Clone()
			bot.Parent=game.Workspace.AllBuilders
			bot.PrimaryPart.CFrame=CFrame.new(Random.new():NextNumber(46,243),3,Random.new():NextNumber(-249.5,57.5))
			print("added guys")
		end
	end
end
game:GetService("UserInputService").InputBegan:Connect(Input)
game:GetService("UserInputService").InputEnded:Connect(Input)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like

Since this is user userinputseerices its a local script and local script can’t access severscript service and severstorage.

1 Like
  1. This will create 6 builders, not 2
  2. You’re attempting to read user input from the server, which will flat out not work.

The client cannot read ServerStorage, nor can it officially create the builders, so swapping to a LocalScript won’t work. You’ll need to incorporate a RemoteEvent:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")


local RemoteEvents = ReplicatedStorage:WaitForChild("RemoteEvents")
local MakeBuilders = RemoteEvents:WaitForChild("MakeBuilders")


local function onInputBegan(input: InputObject, gameProcessedEvent: boolean)
    if gameProcessedEvent then
        return
    end

    if input.KeyCode == Enum.KeyCode.Q then
        MakeBuilders:FireServer()
    end
end


UserInputService.InputBegan:Connect(onInputBegan)
local ReplicatedStorage = game:GetService("ReplicatedStorage")


local RemoteEvents = ReplicatedStorage:WaitForChild("RemoteEvents")
local MakeBuilders = RemoteEvents:WaitForChild("MakeBuilders")


local function onMakeBuilders(player: Player)
    for _ = 1, 2 do
        -- Make a builder.
    end
end


MakeBuilders.OnServerEvent:Connect(onMakeBuilders)

Consider adding a cooldown and limiter too. This is a quick way to allow exploiters to crash your server

the server can’t access the client and your trying to access server storage from the client you gonna need a remote event.

This is a serverscript, and i do not know if i should switch it to Local or not.
Also, youre treating it as a Local script with the “OnServerEvent”.

The first is local, the second is normal. This can be inferred based on the aforementioned inability for the server to use UserInputService, as well as the RemoteEvent

Services to put each one in? Im confused.

ServerScriptService and StarterPlayerScripts

It didn’t work, no change in the number of Builders.

Show the code and your explorer

local ReplicatedStorage = game:GetService("ReplicatedStorage")


local MakeBuilders = ReplicatedStorage:WaitForChild("BuilderMaker")


local function onMakeBuilders(player: Player)
	for _ = 1, 2 do
		local names={"builder","man","guy","brick"}
		local bot=game:GetService("ServerStorage").Builder:Clone()
		bot.Parent=game.Workspace.AllBuilders
		bot.PrimaryPart.CFrame=CFrame.new(Random.new():NextNumber(46,243),3,Random.new():NextNumber(-249.5,57.5))
		bot.Name=names[math.random(1,#names)].." "..names[math.random(1,#names)].." "..names[math.random(1,#names)].." "..names[math.random(1,#names)]
	end
end


MakeBuilders.OnServerEvent:Connect(onMakeBuilders)

Did you add the appropriate event?

Yeah? I didnt name it “MakeBuilders”, just “BuilderMaker”, but i modified the scripts to integrate the different name.

Send the place file. FYI, if you generate the one Random instance, you can simplify the random name generator:

local function generateRandomName(choices: {}): string
    local clone = table.clone(choices)

    RANDOM:Shuffle(clone)

    return table.concat(clone, " ")
end

Here.
builders3.rbxl (142.5 KB)

Your free-cam script is causing the input to be registered as processed by the game. This is because ContextActionService is sinking further responses to that input. I’m not exactly sure why this was done, so changing the return result on line 210 to Enum.ContextActionResult.Pass will resolve the issue. You’ll most likely want to choose a different key though, or remove the absolute absurd number of sank key-bindings associated with that feature-crept free-cam

It works! Thank you for this contribution!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.