This is clientside. So It wouldn’t work as intended/correctly.
local equipped = script.Parent.Handler.Equipped
local selected = script.Parent.Handler.Selected
local location = script.Parent.Handler.Location
local player = game.Players.LocalPlayer
local character = player.Character
local items = {}
local buttons = {}
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,false) -- Makes the original backpack gui invisible
function search(location)
for i,v in pairs(location:GetChildren()) do -- Find all item in a specific location
if v:isA("Tool") then -- If the item found is a "Tool"
table.insert(items,v) -- We're going to put all the tools found in a table.
print("1")
end
end
end
function refresh()
for i,v in pairs(buttons) do -- Finds all items in the table
v:Destroy() -- Destroy 'em all
print("2")
end
for i,v in pairs(items) do -- Finds all items in the table
local button = script.Sample:Clone() -- clones the sample button inside the localscript
button.Name = v.Name -- sets the cloned button's name to the name of the item
button.LayoutOrder = i
button.Parent = script.Parent.Handler -- Sets the parent of the cloned button to the handler
button.Image = v.TextureId -- Sets the image of the button to the texture id of the tool
table.insert(buttons,button) -- Inserts the button to our table "buttons"
print("3")
button.MouseButton1Click:connect(function()
print("4")
if script.Parent.Handler.Selected.Value == nil or script.Parent.Handler.Selected.Value ~= v then -- Checks if the selected value is nothing or if the selected value is not the button
script.Parent.Frame.ItemName.Text = v.Name -- Sets the TextLabel's Text to the name of the tool/button
script.Parent.Frame.ImageLabel.Image = v.TextureId -- Sets the image label's image to the texture id of the tool
script.Parent.Handler.Selected.Value = v
print("5")
if equipped.Value == nil or equipped.Value ~= selected.Value then -- Just the same as the last one
character.Humanoid:UnequipTools() -- Forces the player to unequip the tool that they equipped
print("6")
if location.Value == player.Backpack then
character.Humanoid:EquipTool(selected.Value)
equipped.Value = selected.Value
print('7')
end
else
end
end
end)
end
end
function backpackRefresh()
print("8")
items = {}
search(character)
search(player.Backpack)
refresh()
end
backpackRefresh()
player.Backpack.ChildAdded:connect(backpackRefresh)
player.Backpack.ChildRemoved:connect(backpackRefresh)
character.ChildAdded:connect(backpackRefresh)
character.ChildRemoved:connect(backpackRefresh)
Did you mean to reply to another person?
this is a cool spoiler
I’m screenshoting my output
– useless stuff -
Create a remote event, obviously ratelimit and validate it, and handle equipping on the server.
Is this a localscript?
abcdefghijklm
I would believe so considering there are what I believe to be UI elements being created.
The location value is not player.Backpack, if it isn’t that, then what’s in there? Quite odd for a check like that
Yep it is
This is the alphabet abcde
Considering this is the area it is low the script do not work, I would think it is due to the location thing.
What happens if you remove the if location.Value == player.Backpack then
if statement?
That’s your problem, create a server-sided script and handle a remote event to handle equipping and de-equipping.
Ok now I can equip the tool by removing this line of code.
But the problem is that i can’t remove it
Imma try to check the code again and add a condition
I believe that’s what that condition was for, but I think it was incorrectly handled/placed. You may have to put your own condition to see if a weapon is equipped or not