Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

[SOLVED] Attempt to index nil with backpack?

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

you forgot to index the arg in the function

giveGear(Clicker)

2 comments

0

Thanks

0

Please mark it if you found your answer so people can know that this has been solved

This discussion is preserved as it was. New answers, comments, and votes are closed.