So i have my script so when you step on this part it spawns a 1 npc but idk how i would change it to make it spawn 3.Also when i step on the part its super laggy
Is there any reason this needs to be in a
while true do loop?
Just remove the loop and add a debounce to the script. Also, if you want it to spawn 3 objects, use a
local debounce = false script.Parent.Touched:Connect(function() if not debounce then return end debounce = true for i = 1, 3 do local Clone = game.ServerStorage.ClonePart:Clone() Clone.Parent = workspace Clone.Anchored = false task.wait() end task.wait(5) -- change this to increase/decrease cooldown time debounce = false end)
Clone() doesn’t take any arguments so I don’t know why you have a
1 in there. Additionally,
task.wait() is preferable to
It still spawns 1 guy though.Was i sopposed to change something
Try this one.
-- Put it on your desired part local DesiredNPC = game.ReplicatedStorage:FindFirstChild("NPC") -- local Part = script.Parent local debounce = false local function SpawnNPC(HowMany) -- I did this mainly because for the peoples that don't understand script very well if debounce ~= true then -- If the debounce is false then, it will spawn the NPC about exactly the "HowMany" value debounce = true for i = 1, HowMany do local newNPC = DesiredNPC:Clone() -- Apparantly clone it, like it suggest newNPC.Parent = workspace -- Parent it on the workspace newNPC.PrimaryPart.CFrame = (Part.CFrame * CFrame.new(0,2,0)) * CFrame.new(Part.CFrame.LookVector * -2) -- Make it spawn behind the part task.wait() end task.wait(5) debounce = false end end Part.Touched:Connect(function() SpawnNPC(3) -- You can change the number to whatever you like, for example 5 or 15 end)
Sorry if make some grammar mistakes.