✓ Accepted answer
###The problem lies in the fact that you wrong assume that the wave variable is a reference to the actual property of the IntValue. If the value of the IntValue changes, the variables you have defined won't update; only its Value property will change. In order to fix this, you can remove the wave variable and only make direct accesses to the Value property of the IntValue. You could also modify the variables to hold the IntValue object itself.
local ServerStorage = game:GetService("ServerStorage")
local wave = game.Workspace.Wave
function CreateWave()
local WaveClone = ServerStorage.Wave:Clone()
WaveClone.Parent = game.Workspace
end
wait(1)
while true do
for i = 1, 1 do
if math.random(1, 5) == 2 then
local EClone = ServerStorage.EWave:Clone()
EClone.Parent = game.Workspace
else
if math.random(1, 10) == 2 then
local SnowClone = ServerStorage.GiantSnow:Clone()
SchanowClone.Parent = game.Workspace
else
CreateWave()
end
end
wait(math.random(5, 15))
end
wave.Value = wave.Value + 1
wait(1)
end
###It is important to note the difference between a reference and a value. Think of a reference as holding an actual memory location whilst a value just holds normal information (for example, a boolean). In Lua, for example, tables are passed by reference.
local t1 = {
foo = "abc",
bar = 123,
foobar = true
}
local t2 = {
foo = "abc",
bar = 123,
foobar = true
}
local t1reference = t1
t1.foo = "Hello world!"
print(t1.foo)
print(t1reference.foo)
print(t2.foo)
###The t1 and t1reference variables both hold the same exact table whilst t2 is a different table even though it holds the same values.
###However, data like booleans and numbers are passed via value.
local number = 50
local numberVal = num
number = 25
print(number)
print(numberValue)
local bool1 = false
local bool1Val = bool1
bool1 = true
print(bool1)
print(bool1Val)
###Even though numberValue was set to number, both variables have different memory and so changing one value does not change the other value. Same for the boolean values.