I'm making a text-based game similar to that of bitlife. Anyways, when the character is damaged or loses health, I am trying to make a health bar smaller, to show that the hp has gone down. However, I get this error:
Players.playername.PlayerGui.GUI.MainUI.InformationBar.CharacterStats.LocalScri pt:20: attempt to index number with 'Changed'
Here's the code for that script:
--[[
Here, I define the variables.
]]
local player = game.Players.LocalPlayer
local hp = game:GetService("StarterGui").GUI.MainUI.InformationBar.CharacterStats.Health.HealthValue
local healthStats = hp.Parent
--[[
Here, I set out the functions.
]]
if player then
repeat wait() until game:GetService("StarterGui")
end
healthStats.Health.Text = tostring(hp.Value/2)
hp.Value.Changed:Connect(function(currentHp)
local previousHp = healthStats.HealthBar.Size
previousHp = UDim2.new(previousHp - currentHp)
end)
Thanks for the help!
