This script is supposed to force the player to have a tool equipped, and it works just fine when I put the tool in the starterpack; but when I give the tool to the player from a script, it doesn't always work.
wait(0.001)
EnableBackpackGui = false -- false disables Backpack gui, true enables it.
Weapon = script.Parent.Name
local player = game:GetService("Players").LocalPlayer
local char = player.Character
local tool = player.Backpack:FindFirstChild(""..Weapon.."")
local humanoid = char:WaitForChild("Humanoid")
db=1
while wait() do
if char then
game.StarterGui:SetCoreGuiEnabled(2,EnableBackpackGui)
for i,v in ipairs(char:GetChildren()) do
if v.className ~= ""..Weapon.."" then
wait()
if db == 1 and humanoid.sit == false then
player.Character.Humanoid:EquipTool(tool)
db=2
function onSeated(isSeated)
if db == 2 then
humanoid:UnequipTools()
end
end
end
end
script.Parent.Unequipped:connect(function()
db=1
end)
end
end
end
humanoid.Seated:Connect(onSeated)

1 comment
Can you indent the code properly please?