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

What does "attempted to index number with 'Changed' event" mean?

Asked by 3 years ago

I made a script that would fire whenever a player's leaderboard points changes however its giving me this error:

00:42:37.830 - Workspace.Script:11: attempt to index number with 'Changed'

Does this mean that I can't use numbers with the changed event? This is my entire script if it helps:

game.Players.PlayerAdded:Connect(function(player)

    local leaderstats = Instance.new("Folder") 
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local Points = Instance.new("IntValue")
    Points.Name = "Points"
    Points.Parent = leaderstats

  Points.Value.Changed:Connect(function(Value)
      if Value == 5 then
          game.Workspace.door1.Transparency = 0.5
          game.Workspace.door1.CanCollide = false
        end
    end)
end)

1 answer

Log in to vote
2
Answered by 3 years ago

you are trying to get .changed event on an integer or number value. .Changed is not an event of a integer or string you should instead be doing something like below this might have syntax errors but you should follow it

game.Players.PlayerAdded:Connect(function(player)

    local leaderstats = Instance.new("Folder") 
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local Points = Instance.new("IntValue")
    Points.Name = "Points"
    Points.Parent = leaderstats

  Points.Changed:Connect(function(Value) -- get changed of object not objects value
    if tostring(Value) == "Value" then -- if property is value
        if Value == 5 then
          game.Workspace.door1.Transparency = 0.5
          game.Workspace.door1.CanCollide = false
        end
    end
    end)
end)
2
It's ultimately best to hone in onto the property that changed—the signal activates upon any adjustment. You can do this with Points:GetPropertyChangedSignal("Value"):Connect(callback) Ziffixture 6913 — 3y
0
no, it doesnt really make a difference when you take in to account everything else misha123 83 — 3y
0
Feahren, it's actually better to use .Changed in this instance because we're dealing with Value objects, the .Changed event with only check for changes in the value which uses less resources than the GetPropertyChangedSignal listener. SteamG00B 1633 — 3y
0
Thanks for it Ziffixture. Never before heard about var:GetPropertyChangedSignal("Value"):Connect(callback) ErtyPL 129 — 2y
Ad

Answer this question