Int value not showing when made with instance.new

I want to make it so an int value updates every 0.1 seconds, but the value does not seem to be created, I can’t find it anywhere.
I thought it wasn’t about the value before, so I tried by switching how I was server banning people to a table, I was using a folder with int values of the ids. I do not have any more ideas.

This is how I am creating the int value, please tell me if you need more code.

local LP = game.Players.LocalPlayer

local breathcount = Instance.new("IntValue")

breathcount.Parent = LP
breathcount.Name = "Breathcountdown"
breathcount.Value = 100

local CreatedCount = breathcount.Value

Help is appreciated, also this is my first post in the roblox devfourm.

By the way, no errors on the output.

Perhaps LP is nil? So it just gets parented to nil? Or it could be some other line of code responsible for the issue that you are unaware of…
Welcome to the roblox developer forum btw!

1 Like
local LP = game.Workspace

local breathcount = Instance.new("IntValue")

breathcount.Parent = LP
breathcount.Name = "Breathcountdown"
breathcount.Value = 100

local CreatedCount = breathcount.Value

print(CreatedCount)

when i tried this it worked just fine.

image

1 Like

It is defined before on that script.

local LP = game.Players.LocalPlayer

It’s a localscript.

Perhaps, where is the script located?

Stuff happening in local scripts doesn’t replicate to server. Aren’t you using this for server bans?

The LP is the local player, forgot to say that.
It’s a localscript.

local LP = game.Players.LocalPlayer

Yes, but where do you have the local script

I’ll just send the whole thing.

local LP = game.Players.LocalPlayer
local serverbans = {
	
}

local breathcount = Instance.new("IntValue")

breathcount.Parent = LP
breathcount.Name = "Breathcountdown"
breathcount.Value = 100

local CreatedCount = breathcount.Value

game.Players.PlayerAdded:Connect(function(plr)
	if table.find(serverbans, plr.UserId) then
		plr:Kick("You ran out of air in this server.")
	end
end)


while true do
	if CreatedCount > 0 then
		wait(0.1)
		CreatedCount -=1
	end
	if CreatedCount == 0 then
		table.insert(serverbans, LP.UserId)
		LP:Kick("You have died from running out of air! Please join another server.")
	end
end

It is in a folder in workspace.

Move the script to something like starterplayerscripts

1 Like

https://developer.roblox.com/en-us/api-reference/class/LocalScript

Locals scripts are only able to run in certain areas, you are storing it in workspace therefore it is not running.

You should consider changing this to a server script. One of the reasons would be you probably don’t want exploiters messing with that breath mechanic.

1 Like

Every thing in that script works now, but there is a GUI that is supposed to update when it changes.

image

local plr = game.Players.LocalPlayer
local air = plr:WaitForChild("Breathcountdown")

local GUI = script.Parent
local barexterior = GUI.Bar
local barinterior = barexterior.Bar

local function Update()
	local current = air.Value
	local formula = math.clamp(current/100, 0, 1)
	barinterior:TweenSize(UDim2.new(formula, 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.15, true)
end

air.Changed:Connect(function()
	Update()
end)

Should I make another topic about that and mark your message as the solution?

It’s no issue, let me figure out your other issue.

1 Like

LOL, sorry it took me so long… had a blonde moment with duplicate scripts.

Local Script Located in the same place as yours

local plr = game.Players.LocalPlayer
repeat task.wait() until plr.Character or plr.CharacterAdded:Wait()
local air = plr:FindFirstChild('Breathcountdown', false)

--[[if air then
	print(air.Value)
end]]

local GUI = script.Parent
local barexterior = GUI.Bar
local barinterior = barexterior.Bar

--[[task.spawn(function()
	while task.wait(.5) do
		warn(plr:FindFirstChild('Breathcountdown', false).Value)
	end
end)]]

local function Update()
	local current = air.Value
	local formula = math.clamp(current/100, 0, 1)
	barinterior:TweenSize(UDim2.new(formula, 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.15, true)
end

air:GetPropertyChangedSignal('Value'):Connect(function()
	Update()
end)

Then I have a server script in ServerScriptService that simply moves the value down and parents the value, you don’t have to parent the value it was just for testing purposes.

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		print('char')
		script.Breathcountdown.Parent = plr
		if plr:FindFirstChild('Breathcountdown', false) then
			task.spawn(function()
				while task.wait(1) do
					plr:FindFirstChild('Breathcountdown', false).Value -= 15
					print(plr:FindFirstChild('Breathcountdown', false).Value)
				end;
			end);
		end;
	end);
end);
2 Likes

I replaced the update script with this

and made a new script on serverscriptservice with this

Is that what you were saying?
Edit:
Still not working by the way.

Sorry, forgot to check output, there is an error saying Breathcountdown is not a valid member of Script “ServerScriptService.Script”. line 4

I’ve got to go to bed soon, do you just want me to mark this as the solution and try more by myself tomorrow?