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

Values' "Changed" functions are "nil values?"

Asked by 6 years ago

This is driving me nuts.

For some reason, this script keeps throwing an error saying that the "Changed" event on these values (more specifically as said in the output, the one at line 13) is a "nil value", even though it's right here on the Roblox Wiki:

local stats = script.Parent.Stats; local head = script.Parent.Head

local gender = stats.Gender; local name = stats.Name; local desc = stats.Description

gender.Changed:Connect(function()
    if gender.Value == 1 then
        head.NameGui.TextLabel.Text = name.Value.."?"
    elseif gender.Value == 0 then
        head.NameGui.TextLabel.Text = name.Value.."?"
    end
end)

name.Changed:Connect(function()
    if gender.Value == 1 then
        head.NameGui.TextLabel.Text = name.Value.."?"
    elseif gender.Value == 0 then
        head.NameGui.TextLabel.Text = name.Value.."?"
    end
end)

desc.Changed:Connect(function()
    head.DescriptionGui.TextLabel.Text = desc.Value
end)

With my experience with the "Changed" event (on value instances, FYI), I've never received this error. Why is this happening, and how can I fix it?

0
I won't make this a complete answer because it is more a shot in the dark. Are you sure that gender, name and desc exist? Check if they themselves are nil. Then it's a problem with how you access the objects. Just an idea. User#18718 0 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

The problem is that name is not what you think it is. Instead of getting a reference to what I assume is a StringValue called "Name" inside stats, you are accessing the property stats.Name. When defining name you should do this instead:

local name = stats:FindFirstChild("Name")
Ad

Answer this question