You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
A script that creates 2 builder bots when Q is pressed.
What is the issue? Include screenshots / videos if possible!
It doesn’t work, but theres no error.
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.
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 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
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)
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