Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

"attempt to index number with 'Changed'" error when checking for the .Changed event firing?

Asked by
KingDomas 153
2 years ago
Edited 2 years ago

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!

1 answer

Log in to vote
0
Answered by
KingDomas 153
2 years ago

I solved the error. I simply removed the .Value from line 20. Hope this helps anyone else having this issue.

Ad

Answer this question