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

How do I fix this?

I have this in a local script, inside a textbutton, to equip a tool, the tool is in replicated storage, plsfix

local player = game.Players.LocalPlayer
local pickaxe = player.Backpack:FindFirstChild("Pickaxe")

script.Parent.MouseButton1Click:connect(function(player)
	local pickaxe = player.Backpack:findFirstChild("Pickaxe")
	if script.Parent.Text == "Unequip" then
		pickaxe.Parent = game.ServerStorage
		script.Parent.Text = "Equip"
	else
		pickaxe:Clone().Parent = player.Backpack
		script.Parent.Text = "Unequip"
	end
end)

1 comment

0

Kenny, I read your code until line 2...local pickaxe = player.Backpack:FindFirstChild("Pickaxe")...well, when you equip your pickaxe its no longer in your backpack, it's in your player. so that might be one issue

1 answer

You have player written as a parameter for the function you are connecting to MouseButton1Click, but MouseButton1Click does not give you any parameters, so player is being locally redefined as nil. Change :connect(function(player) to :connect(function()

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