Workspace.Vertires.Chances:10: attempt to index nil with 'Connect' - Server - Chances:10

i got this error and i cant find a way to fix it someone please help

script:


local char = script.Parent
local plr = game.Players:GetPlayerFromCharacter(char)
local Equipped = plr.leaderstats:WaitForChild("Equipped")

local Chances = require(game.ReplicatedStorage.Chances)

local cg = game.ReplicatedStorage.ChanceGUI
local cgc = cg:Clone()
Equipped.Value.Changed:Connect(function()
local RarityName = table.find(Chances, Equipped.Value)
local raritychance = RarityName[2]








cgc.Parent = char.Head
cgc.name.Text = "1 in "..raritychance

end)


1 Like

this line gives error but idk why

1 Like

You do not have an end)

Example:

Equipped.Value.Changed:Connect(function()
	print("EQUIPPED VALUE =", Equipped.Value)
end)
1 Like

The end) is at the bottom of the script.

What is equipped? Is it something like number value?

1 Like

.Changed fires when any property of the given object changes, not a specific one. Use GetPropertyChangedSignal().

Two ways:

Equipped.Changed:Connect(function()
end)

--or

Equipped:GetPropertyChangedSignal("Value"):Connect(function()
end)
1 Like

that worked but this gives an error now

local raritychance = RarityName[2]
1 Like

Workspace.Vertires.Chances:12: attempt to index nil with number - Server - Chances:12

1 Like

Is that a ModuleScript you’re trying to require? If it is, can I see inside of it? If it’s just a table, you might be able to move it to that script.

1 Like

alright
local module = {}

return {
{“Common”, 1},
{“Uncommon”, 5},
{“Rare”, 10},
{“Epic”, 20},
{“Legendary”, 30},
{“Mythical”, 60},
{“Celestial”, 150},
{“Divine”, 300},
{“Galactic”, 500},
{“Universal”, 1000}
}

1 Like

Please keep a backup of your old code - this is untested.
(Assuming RarityName is a string)
RarityName is coming back as nil because you are searching for a number. You can move the module content to this script as well. Try this:

local Chances = {
    ["Common"] = 1,
    ["Uncommon"] = 5,
    ["Rare"] = 10
    ["Epic"] = 20,
    ["Legendary"] = 30,
    ["Mythical"] = 60,
    ["Celestial"] = 150,
    ["Divine"] = 300,
    ["Galactic"] = 500,
    ["Universal"] = 1000
}

This also means you would need to use the following when getting the chance:

local raritychance  = Chances[Equipped.Value]
2 Likes

Oh thanks! it worked (30 letters blah blah blah)

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.