Localscript
local plr = game.Players.LocalPlayer
local backpack = plr.Backpack
local hotbar = script.Parent
local done = false
for i,v in pairs(backpack:GetChildren()) do
if v:IsA("Tool") then
hotbar[i].ImageLabel.Image = v.TextureId
hotbar[i].Tool.Value = v.Name
end
if not backpack:FindFirstChild(hotbar[i].Tool.Value) then
hotbar[i].Tool.Value = nil
hotbar[i].ImageLabel.Image = nil
end
end
backpack.ChildAdded:Connect(function()
for i,v in pairs(backpack:GetChildren()) do
if v:IsA("Tool") then
hotbar[i].ImageLabel.Image = v.TextureId
hotbar[i].Tool.Value = v.Name
end
if not backpack:FindFirstChild(hotbar[i].Tool.Value) then
hotbar[i].Tool.Value = nil
hotbar[i].ImageLabel.Image = nil
end
end
end)
for i,v in pairs(hotbar:GetChildren()) do
if v:IsA("ImageButton") then
if v.ImageLabel.Image ~= nil then
v.MouseButton1Click:Connect(function()
if v.Equipped.Value == false then
v.Equipped.Value = true
done = true
else
v.Equipped.Value = false
done = true
end
game.ReplicatedStorage.EquipTool:FireServer(v.Tool.Value,v.Equipped)
done = false
end)
end
end
end
Serverscript
game.ReplicatedStorage.EquipTool.OnServerEvent:Connect(function(plr,toolName,equipped)
if plr and toolName then
if plr.Backpack:FindFirstChild(toolName) then
local char = plr.Character
local humanoid = char.Humanoid
if char and humanoid then
if equipped.Value == true then
humanoid:EquipTool(plr.Backpack[toolName])
elseif equipped.Value == false then
humanoid:UnequipTools()
end
end
end
end
end)
It doesn’t equip the tool, yet it still sets the values inside of the UI to true and false and the tool name, etc. What am I doing wrong?