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.
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!
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
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.
Every thing in that script works now, but there is a GUI that is supposed to update when it changes.
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)
LOL, sorry it took me so long… had a blonde moment with duplicate scripts.
Local ScriptLocated 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);