#Error in For loop
77 messages · Page 1 of 1 (latest)
just do in the loops
Error in For loop
yes but in ALL for loops
i think the for loops needs in LUAU always an index
so for i, _
fake, you can, but try that
oh
well for loops dont require indexes
cause line 87 is the last line to run and its the only giving an error
is counterdraw a table?
yeah mb
you cant iterate over a number so
and there is saying
attempt to iterate over a nil value
the value is nil
for only works on table tho
and doing like
well slimeList is a table
for i = 1, 10 ...
thigns like that
thats why it aint throwing err there
slimeList[counterDraw] is meant to get the value from slimelist at the counterDraw position
yes but is counterdraw goin to be a table?
no its for i,_ in slimeList[counterDraw]
yeah you're accessing to the counterDraw in the slimelist table
but counterDraw AINT a table
prolly i'll change the for loop because i dont even know what you're trying to do
well just do
for i = 1, slimeList[counterDraw] do
counterDraw is NIL
yeah its 0
its 0
?
i see many problems here of logic
You're accessing to that table with counterDraw, that is 0, and theres NO thing that is 0
All I need is for it to run for however many times the value of the slimelist is, if its 0 it skips it
just do for i = 1, counterDraw do ...
yeah but it needs to be at the specific position
of counterDraw
slimeList[counterDraw}
if counterDraw was 1
and slime1= 3 the loop would need to run 3 times
yeah then u may re write some things
just rest a bit and think about it when u want i cant help without knowing anything more
alr ill wait for someone else who knows about for loops more thanks for your help
its not about knowing...
i cant do shit without understanding what you're trying to do
u cant stay here sitted waiting for someone
I gave you the entire code
go on and research
yes and the entire code have so many logic problems
if i was you just re write the entire thing in a chill moment and understanding what im doing
okay well just saying it has errors without saying what errors is not at all helpful
you was trying for example accessing to the table with a value that doesnt exist in the table, for loops confusing idk
is just to make a look
-- Sorry if this script isnt the most optimized its my first time doing a system like this lol
local model = script.Parent
local addSlime = model:WaitForChild("AddSlime")
local mergeSlimes = model:WaitForChild("MergeSlimes")
local Slimes = model:WaitForChild("Slimes")
local cubby = model:WaitForChild("Cubby")
local slimeStorage = model:WaitForChild("SlimeStorage")
local slimeCounter = 0
local distanceBetweenSlimes = 2 --Amount of studs between each slime horizontaly
local touching = false
local money = 1000 -- change to wherever you have the money system at
local slimeCost = 1 -- initial slime cost
local slimeCostModifier = 1.15 -- What to multiply the price by each time
local mergeAmount = 3 --change to however many are needed to merge
local slimePerLayer = 5-- self explanetory
local slimeList = {-- amount of these dont matter just put all the slimes you have in the Slimes folder
["slime1"] = 1,
["slime2"] = 0, -- Just add a new variable like this for each new slime along with each slime model in the Slimes folder not slimestorage
["slime3"] = 0,
["slime4"] = 0,
["slime5"] = 0,
["slime6"] = 0,
["slime7"] = 0,
["slime8"] = 0,
["slime9"] = 0,
["slime10"] = 0,
["slime11"] = 0,
}
addSlime.Touched:Connect(function()
if touching == false then
touching = true
if money >= slimeCost then
money -= slimeCost
slimeList.slime1 += 1
slimeCost = slimeCost * slimeCostModifier
draw()
end
end
end)
addSlime.TouchEnded:Connect(function()
touching = false
end)
mergeSlimes.Touched:Connect(function()
local counterMerge = 0
for _ in slimeList do
counterMerge += 1
if slimeList[counterMerge] >= mergeAmount then
slimeList[counterMerge + 1] += math.floor(slimeList[counterMerge]/mergeAmount)
end
end
draw()
end)
function draw()
print("Drawing")
local counterDraw = 0
local layerCounter = 0
local X = Slimes.StartPos.Position.Z-- this depends on the orientation you can change the z to a x if you orient it differently I think
local Y = Slimes.StartPos.Position.Y
for _ in pairs(Slimes:GetDescendants()) do
counterDraw += 1
print("Counter Draw adding")
end
for _ in slimeList do
if layerCounter == slimePerLayer then
layerCounter -= slimePerLayer
local cubbyClone = cubby:Clone()
cubbyClone.Parent = cubby.Parent
cubbyClone.Position =cubby.Position + Vector3.new(0,cubby.Size.Y,0)
Y += cubby.Size.Y
X = Slimes.StartPos.Position.Z -- same as last comment on orientation
end
if slimeList[counterDraw] ~= nil then
for i=1,slimeList[counterDraw] do
print("Cloning")
layerCounter += 1
local Clone = Slimes:WaitForChild("Slime " .. counterDraw):Clone()
Clone.Parent = model.SlimeStorage
Clone.Transparency = 0
Clone.Position = Vector3.new(Slimes.StartPos.Position.X,Y,X) -- change 23 to wherever you have and flip around the X and slimes start position depending on orientation and change the X to a Z
X += Slimes.StartPos.Size.Z + distanceBetweenSlimes
end
else
repeat
counterDraw -= 1
until slimeList[counterDraw] ~= nil or counterDraw == 0
counterDraw += 1
end
counterDraw -= 1
end
end
Kinda fixed it but I got a different issue now it times out and gives the error 12:06:54.778 Workspace.Slime thing.Script:40: Script timeout: exhausted allowed execution time - Server
the repeats need a wait, is liek a bucle so it needs a wait to dont crash
why is it all nil when we are adding one to slime1 in the table?