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

how to make the parts spawn one at a time?

Asked by 4 years ago
Edited 4 years ago

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

Log in to vote
0
Answered by
DesertusX 435 Moderation Voter
4 years ago
Edited 4 years ago

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!

0
I mean I meant that the parts should spawn one at a time but you simplified the code so thanks anyway :) AtrocityPrevails 49 — 4y
0
No problem! Happy to help! DesertusX 435 — 4y
0
I edited the script. Is something like that what you meant? DesertusX 435 — 4y
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. AtrocityPrevails 49 — 4y
0
Okay, that's good to hear! DesertusX 435 — 4y
Ad

Answer this question