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

Attempt to index nil with 'Connect'?

Asked by 2 years ago

Error : attempt to index nil with 'Connect'

Local Script:

local BarPercent = script.Parent.Rank.Rank
local Coins = script.Parent.Coins
local Gems = script.Parent.Gems
local Rank = script.Parent.Rank.TextLabel
local plr = game.Players.LocalPlayer
local x = require(game.ReplicatedStorage.BigNum)



plr.stats.Rank.Value.Changed:Connect(function()
print("Hello World!")
end)

2 answers

Log in to vote
1
Answered by 2 years ago
Edited 2 years ago

I think you meant:

plr:WaitForChild("stats").Rank:GetPropertyChangedSignal('Value'):Connect(function()
    print("Hello World!")
end)

Use GetPropertyChangedSignal

https://developer.roblox.com/en-us/api-reference/function/Instance/GetPropertyChangedSignal

Properties have no events

Used WaitForChild in case it takes a while to load

Edit: Have no idea why a few letters of the code is cut out...

Ad
Log in to vote
0
Answered by 2 years ago

You will need to wait for the object to load. Try using a WaitForChild() instead.

plr:WaitForChild("stats"):WaitForChild("Rank").Value.Changed:Connect(function()
    print("Hello World!")
end)

This isn't the best practice, but you get the point.

Answer this question