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

How do I fix this?

Asked by 8 years ago

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)
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 Xoqex 75 — 8y

1 answer

Log in to vote
0
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
8 years ago

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()

Ad

Answer this question