New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

It's giving me this error. "Attempt to index a nil value" Line 7?

Asked by
Jxdenx 43
5 months ago
Edited 5 months ago

So, basically I'm having trouble trying to get the reward to be given to the player.

local human = script.Parent:WaitForChild("Humanoid")


human.Died:Connect(function()
    local tag = human:FindFirstChild("creator")
    if tag ~= nil then
    local stats = game:GetService("Players"):FindFirstChild(tag.Value).leaderstats
        if stats then
            print("heres ur money")
            Gold.Value = Gold.Value+script.Parent.Settings.Gold.Value
        end
    end
end)
0
that indentation at the second end of the touched event.... LoganboyInCO 150 — 5mo
0
use FindFirstChild() or WaitForChild() with a timeout instead of indexing leaderstats BashCaster 2670 — 5mo
0
Nothing worked, it still says "Attempt to index a nil value" Jxdenx 43 — 5mo

1 answer

Log in to vote
0
Answered by 5 months ago
Edited 5 months ago

Try this:

 script.Parent:WaitForChild("Humanoid").Died:Connect(function()
    local tag = human:FindFirstChild("creator")
    if tag ~= nil then
    local stats = game:GetService("Players").leaderstats:WaitForChild(tag.Value)
        if stats then
            print("heres ur money")
            Gold.Value = Gold.Value + script.Parent.Settings.Gold.Value
        end
    end
end)
0
Doesn't work, and btw line 4 is incorrect. Jxdenx 43 — 5mo
Ad

Answer this question