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

Why won't the player's backpack autoequip by clicking a gui?

Asked by
thePyxi 179
8 years ago

I'm trying to make the player, whenever he/she clicks a gui button, equip a tool from the player's backpack. It says it keeps failing at line 15. The error is listed below. Can someone explain to me why it is giving me an error? (Yes, it is in a LocalScript.)

Error: Players.Player1.PlayerGui.Backpack.ScrollingFrame.AutoEquip:15: attempt to index global 'findval' (a nil value)

01game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
02 
03local player = game.Players.LocalPlayer
04local character = player.Character
05local tool = player.Backpack:GetChildren()
06 
07val = script.Parent.EquipedItem.Value
08findval = player.Backpack:FindFirstChild(val)
09 
10function equip(tool)
11    findval:Clone().Parent = character
12end
13 
14function unequip(tool)
15    findval:Destroy()
View all 24 lines...

1 answer

Log in to vote
0
Answered by
Cuvette 246 Moderation Voter
8 years ago
Edited 8 years ago

An easier way to do this would be how I've done it below assuming the LocalScript is inside the button of the Gui.

1TOOLHERE = game.Players.LocalPlayer.Backpack["SwordOrSomething"]
2 
3script.Parent.MouseButton1Down:connect(function()
4    game.Players.LocalPlayer.Character.Humanoid:EquipTool(TOOLHERE)
5end)

to un-equip the tools you might as well use this line it's just nice and simple. I'm not saying this is the best way to do it I'm just giving you an easier option to what you have already.

1game.Players.LocalPlayer.Character.Humanoid:UnequipTools()

There are plenty more people on here that can explain this better than me.

Ad

Answer this question