_G variable is not working

I am trying to create a cool down for my walki-talki, I use a global variable to hold a cooldown value, but for some reason it is not working.

It keeps saying cooldown is enabled but cooldown is set to false

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

Settings script:

_G.cooldown = 5 --Change this to the walki-talki cooldown

_G.onCooldown = false --Don't touch this or the Walki-Talkies will break

Main script:

	if _G.cooldown == false then
		_G.cooldown = true
		_G.cooldown = false
		print('Cooldown is enabled!')

Any idea of what the problem is??

First potential issue

You were using _G.onCooldown for your boolean variable so if _G.cooldown will equal 5

Second potential error, is that I’m pretty sure that _G doesn’t replicated between the server and client, so that could bring a potential issue.

1 Like

Ok, I will use a bool variable, instead of global. Thanks!

Bool variables also do not replicate. You need to use a remote event.

Already fixed it by using a boolvalue. It works now.