Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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

This discussion is preserved as it was. New answers, comments, and votes are closed.