Hi, I am trying to add a number to i but it’s not working, does anyone know how I can fix this?
for i = length, 0, -1 do
game.ReplicatedStorage.Events.TaskCompleted.OnServerEvent:Connect(function(player, TaskName, Innocent, Murderer)
if Innocent == true then
print("innocent true")
i = i - 15
else
print("murderer true")
i = i + 20
end
end)
end
AFAIK you can’t change the i in a for loop, therefore you can use a while loop to achieve the same thing.
local i = length
while i >= 0 do
--do stuff here
i -= 1
end
And why do you need to OnServerEvent it multiple times? I’m confused with what you are doing here.
And also you can use value += increment and value -= increment.
The default start time is 600 seconds, if the event is fired, it’ll go up or down by an extraordinary time when i just need it to increase or decrease by 20 or 15 seconds respectively
Ah, so you are connecting a new OnServerEvent event every time the while loop runs. Here’s the fix:
local i = length
game.ReplicatedStorage.Events.TaskCompleted.OnServerEvent:Connect(function(player, TaskName, Innocent, Murderer)
if Innocent == true then
print("innocent true")
i -= 15
else
print("murderer true")
i += 20
end
end)
while i >= 0 do
wait(1) -- Hope I am not wrong about this
i -= 1
end