Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

how to make the parts spawn one at a time?

Hey, just started scripting today and I was just playing around with code when I got this idea but I don't know how I would do it. So the idea is to make the parts spawn one at a time while the user is touching another part and if they stop touching the part then the parts that spawned all get removed. I got the second part of my idea done, just need help with the first one. Here's my code so far:

function onTouched(player)
	local humanoid = player.parent:FindFirstChild("Humanoid")
	if (humanoid ~= nil)
	then
		local test = Instance.new("Part")
		test.Parent = game.Workspace
		test.Position = Vector3.new(0,0,0)
		test.Size = Vector3.new(5,5,5)
		wait(5)
	end
end

function onTouchedEnded()
	local yurr = game.Workspace:FindFirstChild("Part")
	yurr:Destroy()
	print("ez clap")
end
script.Parent.Touched:Connect(onTouched)
script.Parent.TouchEnded:Connect(onTouchedEnded)

1 answer

✓ Accepted answer

Here is the fixed version:

local ended  = false

function onTouched(player)
local humanoid = player.Parent:FindFirstChild("Humanoid") --Parent must have a capital "P"
if humanoid
then --Simpler way to say it and without ()
while not ended do
wait()
local test = Instance.new("Part")
test.Parent = game.Workspace
test.Position = Vector3.new(0,0,0)
test.Size = Vector3.new(5,5,5)
end
end
end
	 
function onTouchedEnded()
local yurr = game.Workspace:FindFirstChild("Part")
yurr:Destroy()
ended = true
print("ez clap")
end
script.Parent.Touched:Connect(onTouched)
script.Parent.TouchEnded:Connect(onTouchedEnded)

Don't forget to accept the answer if I helped!

5 comments

0

I mean I meant that the parts should spawn one at a time but you simplified the code so thanks anyway :)

0

No problem! Happy to help!

0

I edited the script. Is something like that what you meant?

1

No but that's a very cool script to experiment with, thanks! Btw there's an error in line 8 but the script still works.

0

Okay, that's good to hear!

This discussion is preserved as it was. New answers, comments, and votes are closed.