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

How to set an Item Limit for a script spawning parts using Values?

local part = script.Parent.Part
local itemSpawn = workspace.ItemSpawned
local item = script.Parent.CurrentItem.Value

repeat
	wait(5)
	local clone = part:Clone()
	clone.Position = Vector3.new(0,0.525,0)
	clone.Transparency = 0
	clone.CanCollide = true
	clone.Parent = itemSpawn
	item = item + 1
until item == 20

The above script spawns a part that can be picked up until it spawned 20

There's another script that when the part is touched, the part get destroyed, and the currentItem.Value goes down by 1, but that is not working

local item = workspace.ItemSpawn.CurrentItem.Value

script.Parent.Touched:Connect(function)
	item = item - 1
	script.Parent:Destroy()
end)

P.S. The question was edited to fit the script I rewrote a bit

1 answer

✓ Accepted answer

Let me make your code easier

local part = script.Parent.Parent:FindFirstChild("Item").Part
local currnetItem = game.ReplicatedStorage:FindFirstChild("CurrentItem").Value

for i = 20, 1, -1 do
local clone = part:Clone()
clone.Parent = workspace
clone.Position = (put your position here)

It's much easier to just use a for loop.

2 comments

0

The code is also probs running before the part gets inserted

0

@SuperLittleAdmin why do you have multiple scrips? anyways just copy and paste the code but change the variables

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