This won't run for some reason

Hello, I have a gui and a local script in it will not run for some reason.
I have a module script too, here is it:

local items = {
	maxOxygen = 100,
	oxygen = 100
}

return items

And here is the localscript:

local player = game:GetService("Players").LocalPlayer
player.CharacterAdded:Wait()

local char = player.Character

local module = require(script.Parent.Parent.oxygen)

local maxOxygen = module.maxOxygen
local oxygen = module.oxygen

while true do
	task.wait()
	oxygen -= 1
	script.Parent.Text = (oxygen .. "%")
	print(oxygen)
	if oxygen < 1 then
		player:Kick()
		break
	end
end

It won’t run for some reason.(the while true won’t)

Maybe change the require module to :FindFirstChild(“okygen”)

If the module script is inside ServerScriptService, you won’t be able to require it from a LocalScript, so you’ll have to move the module script to ReplicatedStorage.

If that isn’t the issue, then look in the output for any errors and place some print statements in your code to detect when it stops running.

I tried this, but it still won’t work. There are no errors or output at all.

Can you send a screenshot with the location and name of the module?

Here is a screenshot of my explorer:

Try this code:

local RS = game:GetService("ReplicatedStorage")
local player = game:GetService("Players").LocalPlayer
player.CharacterAdded:Wait()

local char = game.Workspace:WaitForChild(player.Name) or player.Character or player.CharacterAdded:Wait()

local module = require(RS.oxygen)

local maxOxygen = module.maxOxygen
local oxygen = module.oxygen

while true do
	task.wait()
	oxygen -= 1
	script.Parent.Text = (oxygen .. "%")
	print(oxygen)
	if oxygen < 1 then
		player:Kick()
		break
	end
end

What is this maxOxygen variable?

It is a variable inside the module script…

That was just me planning ahead because I wanna add a progress bar that will use it.

Yes, it is inside the module script.

Oh right, sorry I’m like dead right now

This didn’t really work, it still won’t run. Perhaps I should share my game file. Here
Oxygen.rbxl (42.0 KB)

I know the problem now, let me update the code brb

On line 13, remove the -= operator and just make it oxygen = oxygen - 1

Why? That’s just extra code, and roblox uses luau.

Uhhhh, that is Luau. What that line does is checks the current value of the oxygen variable and then subtracts 1 by the current amount

1 Like

I think the character was already added by the time you called this.

Oxygen.rbxl (41.9 KB)

Your problem has been fixed…

If he doesn’t want it to drain fast then add task.wait(5)