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)
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!