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

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

Asked by 5 years ago

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

Log in to vote
1
Answered by 5 years ago

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.

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. GarryGecko99 30 — 5y
0
Heh, robloxdev.com User#19524 175 — 5y
Ad
Log in to vote
1
Answered by 5 years ago

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.

0
How can I set it as a NumberValue? GarryGecko99 30 — 5y
0
You set it to one by creating it from Instance.new like my answer. User#19524 175 — 5y

Answer this question