Help make Number Variable Update depending up Number value

Hello, how would i make this Variable Update mid script to a Number value?

local MaxStamina = game:WaitForChild("ReplicatedStorage"):WaitForChild("Blizzard"):WaitForChild("ColdValue").Value

it only stays as what it is but when it gets changed it still stays the same

1 Like

What type of value is that? I’m not exactly sure what you mean, but you can use tonumber() if that’s a string that’s only a number.

what do u mean what type of value is it? the MaxStamina controls how much Stamina u have for the whole script and i want to change it depending where u are so i made it based off the a number value but it doesnt update

It’s hard to tell what the issue is without more code or a video demonstration. But from what it sounds like, you’re probably managing a server-side property client-side, where it won’t replicate to the server.


-- Variables

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()

-- Tweens
local TS = game:GetService("TweenService")
local Tweeninfo = TweenInfo.new(2, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
local FreezingTween = TweenInfo.new(5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)

local ColdColor = {
	BackgroundColor3 = Color3.fromRGB(196, 255, 251)
}

local WarmColor = {
	BackgroundColor3 = Color3.fromRGB(255, 101, 96)
}

local Freezing0 = {
	ImageTransparency = 0
}


local Freezing1 = {
	ImageTransparency = 1
}

local UDied = {
	ImageTransparency = 0
}


local UDiedText = {
	TextTransparency = 0
}

local ColdTween = TS:Create(script.Parent.StaminaBar.BlueFrame,Tweeninfo,ColdColor)
local WarmTreen = TS:Create(script.Parent.StaminaBar.BlueFrame,Tweeninfo,WarmColor)
local Freezing0 = TS:Create(script.Parent.Freezing,FreezingTween,Freezing0)
local Freezing1 = TS:Create(script.Parent.Freezing,FreezingTween,Freezing1)
local Death = TS:Create(script.Parent.Death,Tweeninfo,UDied)
local DeathText = TS:Create(script.Parent.Death.TextLabel,Tweeninfo,UDiedText)

-- Tweens

-- For the Stamina
local isSprinting = false

local MaxStamina = game:WaitForChild("ReplicatedStorage"):WaitForChild("Blizzard"):WaitForChild("ColdValue").Value
local stamina = MaxStamina

local staminaBar = script.Parent:WaitForChild("StaminaBar")

-- Functions
local function sprint(SType)
	local humanoid = char:FindFirstChild("Humanoid")
	if SType == "Began" then
		isSprinting = true
	elseif SType == "Ended" then
		isSprinting = false
	end
end

-- Stamina: Check if it on moblie

-- For PC

local hotValue = game.Players.LocalPlayer.PlayerGui.Uis.ColdOrHot.HotValue

local function Update()
	if hotValue.Value == false then
		sprint("Began")
	else
		sprint("Ended")
	end
end

hotValue.Changed:Connect(Update)



-- Updating
game:GetService("RunService").RenderStepped:Connect(function()
	local humanoid = char:FindFirstChild("Humanoid")

	if stamina == 0 or stamina == 1 then
		humanoid.Health = nil
		Death:Play()
		DeathText:Play()
		wait(2)
		script.Parent.Death.Visible = false
		stamina = 700
	end
	
	if isSprinting then
	if stamina == 400 then
		humanoid.WalkSpeed = humanoid.WalkSpeed - 4
			ColdTween:Play()
			Freezing0:Play()
		end
	end

	if isSprinting then
		stamina = stamina - 1 -- Run
	else
		stamina = stamina + 1 -- Rest
		if stamina == 401 then
			WarmTreen:Play()
			Freezing1:Play()
			humanoid.WalkSpeed = humanoid.WalkSpeed + 4
		end
	end
	
	stamina = math.clamp(stamina,0,MaxStamina)
		staminaBar.BlueFrame.Size = UDim2.new(stamina/MaxStamina,0,1,0)
end)


while wait() do
	print(MaxStamina)
end

so what im trying to do is this, blizzards will form randomly around the map and when they do i want the players Stamina to Decrease to a smaller dumber, when its over it increases back to the normal

so i made the max stamina a replicated storage value and when a blizzard appears the value gets changed to a smaller number

Assuming that the values are being changed server-side, it looks like this should work. Are there any errors of any kind or something?

well the script isnt updating the value, i need a way for it to update it


local hotValue = game.Players.LocalPlayer.PlayerGui.Uis.ColdOrHot.HotValue

local function Update()
	if hotValue.Value == false then
		sprint("Began")
	else
		sprint("Ended")
	end
end

hotValue.Changed:Connect(Update)

this is getting updated but idk how to do it for this


local MaxStamina = game:WaitForChild("ReplicatedStorage"):WaitForChild("Blizzard"):WaitForChild("ColdValue").Value

i dont know how to use the .Changed but i tried this and it dident work lol

local MaxStamina = game:WaitForChild("ReplicatedStorage"):WaitForChild("Blizzard"):WaitForChild("ColdValue").Value

game:WaitForChild("ReplicatedStorage"):WaitForChild("Blizzard"):WaitForChild("ColdValue").Changed:Connect(MaxStamina)

Store the reference to the object instead:

--not using .Value here
local MaxStamina = game:WaitForChild("ReplicatedStorage"):WaitForChild("Blizzard"):WaitForChild("ColdValue")

--will show the current value
print(MaxStamina.Value)

it always prints out the same even if i change the value

Did you notice I removed .Value from the MaxStamina variable? Also make sure you are changing it on the server if it’s a server script, else the results wont be valid.

yes i noticed u removed .Value but its not gonna change anything, i already know what its gonna print

Also to see the value changing you can wrap it inside a .Changed event:

MaxStamina.Changed:Connect(function()
	print(MaxStamina.Value)
end)

ok i made it where the value is the inside of the script so i put a script inside of the value with a onclient remote event to change the value

the value changes but in the script it doesnt