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

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

Asked by 3 years ago
Edited 3 years ago
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

Log in to vote
1
Answered by
zane21225 243 Moderation Voter
3 years ago

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.

0
The code is also probs running before the part gets inserted zane21225 243 — 3y
0
@SuperLittleAdmin why do you have multiple scrips? anyways just copy and paste the code but change the variables zane21225 243 — 3y
Ad

Answer this question