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

[SOLVED] Attempt to index nil with backpack?

Asked by
Cffex 0
3 years ago
Edited 3 years ago

What I'm try to do is, when player press an object, the object will be destroyed and 2 tools in replicated storage will be given to player who press the object, but somehow, the output say the same thing as the title, Here is the SERVER SCRIPT:

local GrassTool = game:GetService("ReplicatedStorage").Storage.Tools.Grass:Clone()
local LogTool = game:GetService("ReplicatedStorage").Storage.Tools.Log:Clone()
local Tree = script.Parent.Parent
local ObtainedFolder = game:GetService("ReplicatedStorage").Storage.ObtainedObject
local HealthBar = game:GetService("ReplicatedStorage").Storage.Gui.NormalTree.TreeHealthGui:Clone()

function giveGear(player)
    LogTool.Parent = player.Backpack
    GrassTool.Parent = player.Backpack
end

function onClick(Clicker)   
    HealthBar.Parent = Clicker.PlayerGui
    HealthBar.Enabled = true
    Tree.Health.Value -= 1

    if Tree.Health.Value == 0 then
        giveGear()
        HealthBar.Enabled = false
        HealthBar:Destroy()
    else
        --Nothing
    end
end

script.Parent.MouseClick:Connect(onClick)  

Any help would be appreciated!

1 answer

Log in to vote
0
Answered by 3 years ago

you forgot to index the arg in the function

giveGear(Clicker)
0
Thanks Cffex 0 — 3y
0
Please mark it if you found your answer so people can know that this has been solved gamingwithjbthepro 76 — 3y
Ad

Answer this question