Hey guys,
I’m having a problem with int value, I want the value number to increase of 1 each wait(time), everything work, no error, all print show me everything good including the print(number) but the issue is that in the explorer i do not see the int value changing, it stays at 0.
Here the script:
local Interaction = Carton.Interaction
local Configuration = Interaction.Configuration
local Time = Configuration.Temps.Value
local Number = Configuration.Nombre.Value
local Max = Configuration.Max.Value
if Configuration.Activation.Value == "True" then
print("Spawn activation")
while true do
print("Spawn while")
if Number < Max then
print("Spawn Spawn")
Number = Number + 1
print(Number)
end
wait(Time)
end
end
Thats actually really weird… I’m not sure a while true loop is the best decision there though, as it will prevent you from executing any code past that later on.
if Configuration.Activation.Value == "True" then
print("Spawn activation")
while Number < Max do
print("Spawn while")
-- Number += task.wait(Time) -- Returns the actual time waited.
Number += 1 -- Add 1
print("Spawn Spawn")
print(Number)
task.wait(Time) -- Remove this wait if you use the wait listed above
end
end
I don’t see any reason for the code you showed before to not work, nor this one.
Sidenote: Why is Activation.Value a string ‘True’ instead of true?
When you assign a variable it will be either copied or referenced. Base types (number, string, boolean) are copied and later edits to the variable do not effect the original.
When you write
local Number = Configuration.Nombre.Value
This copies the .Value to Number, so further edits to Number do not change the Nombre.Value. Instead you want to get a reference and change the .Value directly like so
local Interaction = Carton.Interaction
local Configuration = Interaction.Configuration
local Time = Configuration.Temps.Value
local Number = Configuration.Nombre -- removed .Value
local Max = Configuration.Max.Value
if Configuration.Activation.Value == "True" then
print("Spawn activation")
while true do
print("Spawn while")
if Number.Value < Max then -- add .Value to the call-site
print("Spawn Spawn")
Number.Value += 1
print(Number.Value)
end
wait(Time)
end
end
Try out types of variables with the typeof() function like so:
print( typeof(Configuration.Nombre) ) -- Instance/IntValue
print( typeof(Configuration.Nombre.Value) ) -- number