Hi! I am making a hotbar system. I already have an inventory system which you can put the tools in the hotbar. When you equip the tools in the inventory it works, but when you press on the slot in the hotbar it doesnt work even though they use the same script? All the prints fire correctly but it is not giving the character the tool. Please help.
local button = script.Parent
local plr = game.Players.LocalPlayer
local selected = script.Parent:WaitForChild("Selected")
local equipped = script.Parent.Parent.Parent.Frame.Handler.Equipped
local location = script.Parent.Parent.Parent.Frame.Handler.Location
button.MouseButton1Click:Connect(function()
if plr and plr.Character then
local character = plr.Character
if equipped.Value == nil or equipped.Value ~= selected.Value then
character.Humanoid:UnequipTools()
print("Tool")
if location.Value == plr.Backpack then
print("HOT BAR1:".. button:FindFirstChild("Selected").Value.Name)
character:WaitForChild("Humanoid"):EquipTool(selected.Value)
equipped.Value = selected.Value
print("Equipping Tool")
end
else
character.Humanoid:UnequipTools()
equipped.Value = nil
print("Unequipping tool")
end
character.Humanoid:UnequipTools()
end
end)
I think that’s why? Equipped Tools in a Local Script can play a bit wonky at times (Which could potentially break the entire script), I think you could try a RemoteEvent to get the Player there instead?
I worked it out now it was because I was equipping a different tool than before so it instantly equips it and unequips it. Also, I did not try and equip a string I equipped an instance in a object value which is a tool.