I have been attempting to create a weapon switching system, but there have been multiple glitches, for example, you can only switch weapons once. Here is the code.
script.Parent.OnServerEvent:Connect(function(player, effect)
if effect=="NextItem" then
print("effenet")
player.Character:FindFirstChildOfClass("Humanoid"):UnequipTools()
local numberon=0
local Children = player.Backpack:GetChildren()
print(numberon==player.Character.ToolOn.Value)
if numberon==player.Character.ToolOn.Value then -- false
numberon+=1
if Children[numberon]:IsA("Tool") then
print("Tool = " .. player.Character.ToolOn.Value)
print("NumberOn = " .. numberon)
player.Character:FindFirstChildOfClass("Humanoid"):EquipTool(Children[player.Character.ToolOn.Value])
player.Character.ToolOn.Value=player.Character.ToolOn.Value+1
if player.Character.ToolOn.Value==(#Children) then
player.Character.ToolOn.Value=0
numberon=0
print("reset sucessful")
end
end
end
end
end)
The server event is firing, I have checked. I haven’t been able to solve this. Thank You!