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

attempt to index local 'lives' (a number value)?

I keep getting an error no matter how many ways I try and define lives. Any ideas why this keeps happening?

while _G.Lives == nil do wait() end
lives = _G.Lives

lives.Changed:connect(function(NewValue)
    if _G.Lives <= 2 then
	textBox.Text = "test"
end
end)

2 answers

✓ Accepted answer

###This is because lives is not an object, it’s a number. Variables don’t have changed events. Make lives an IntValue or NumberValue and it should work.

local lives = Instance.new"IntValue"
lives.Name = "Lives"
lives.Parent = game.Workspace -- put wherever

lives.Changed:Connect(function(newVal)
    if newVal <= 2 then
        textBox.Text = "test"
    end
end)

###On a side note, use Connect, as ROBLOX may remove connect in the future.

2 comments

0

Worked, thank you so much. How did you learn all this stuff? I keep trying to experiment with things to learn but I'm really struggling with finding some good learning materials that are Roblox specific.

0

Heh, robloxdev.com

Looks like it thinks lives is a number value such as 10 or 20, not a NumberValue as in the object you can use the .Changed event on.

2 comments

0

How can I set it as a NumberValue?

0

You set it to one by creating it from Instance.new like my answer.

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