So I’ve had and been having a problem trying to make a script that only makes the character able to equip one tool at once as there is a glitch with one of the tools which I cannot fix. No don’t ask me to fix that glitch because fixing this would be easier.
So I made this code using a server script, located in ServerScriptService and I’m getting no response in the output at all.
game.Players.PlayerAdded:Connect(function(plr)
local chr = game.Workspace:WaitForChild(plr.Name)
if plr then
while true do
wait(.001)
local checked = 0
local get = chr:GetChildren()
for i = 1, #get do
local getc = get[i]
if getc:IsA('Tool') then
checked = checked + 1
end
end
if checked > 1 then
chr.Humanoid:UnequipTools()
end
end
end
end)
It’s intended purpose is to unequip all tools from the character if more than 1 is equipped. Thank you for your time and I would love help on this :>
It isn’t exactly necessary to encase your checking thru a loop, you could just use a ChildAdded event on the Character instead & check if it’s a tool or not
chr.ChildAdded:Connect(function(NewChild)
local Checked = 0
local Objects = chr:GetChildren()
for i = 1, #Objects do
local Check = Objects[i]
if Check:IsA("Tool") then
Checked += 1
end
end
if Checked > 1 then
chr.Humanoid:UnequipTools()
end
end)
Also you could just use a CharacterAdded event as well?
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(chr)
local tools = 0
local humanoid = chr:WaitForChild('Humanoid')
chr.ChildAdded:Connect(function(child)
if child:IsA('Tool') then
tools += 1
if tools > 1 then
humanoid:UnequipTools()
end
end
end)
chr.ChildRemoved:Connect(function(child)
if child:IsA('Tool') then
tools -= 1
end
end)
end)
end)
I’m using SolarHorizon’s lightsabers, you can do a thing called stacking them which is super easy and if you have more than one lightsaber it make you insanely OP.
local tools = 0
char.ChildAdded:Connect(function()
curTools = 0
for i,v in pairs(char:GetChildren()) do
if v:IsA("Tool") then
curTools += 1
end
end
tools = curTools
if tools > 1 then
tools = 0
char.Humanoid:UnequipTools()
end
end)
I only just included a snippet of code as an example
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
local Humanoid = Character:WaitForChild("Humanoid")
Character.ChildAdded:Connect(function()
local Checked = 0
local Objects = Character:GetChildren()
for i = 1, #Objects do
local Check = Objects[i]
if Check:IsA("Tool") then
Checked += 1
end
end
if Checked > 1 then
chr.Humanoid:UnequipTools()
end
end)
end)
end)
You could just mark my post as a solution if it worked for you in case anyone else struggles with this issue as well @R0mAAn1CH was only stating that I added an additional CharacterAdded event & I fixed a couple of other things as well