Nah it is a hobby project of 5 people which we all put our entire hearths in for no profit.
Upon excluding the for loop the script does grant the correct weapons that the player switched to in the menu UI.
(I made some changes to try it differently but didn’t work)
RefreshArsenalEvent.Event:Connect(function(player, Weapon)
local inventory = player.Backpack:GetChildren()--[[
print(inventory)
for a, tool in pairs(inventory) do
print(tostring(tool))
if CS:HasTag(tool, "Weapon") then
tool:Destroy()
end
end
print(inventory)]]
local primaryWeapon = ServerStorage:FindFirstChild(player:WaitForChild("Database"):WaitForChild("PrimaryWeaponData").Value)
local secondaryWeapon = ServerStorage:FindFirstChild(player:WaitForChild("Database"):WaitForChild("SecondaryWeaponData").Value)
if primaryWeapon and secondaryWeapon then
local primaryClone = primaryWeapon:Clone()
local secondaryClone = secondaryWeapon:Clone()
primaryClone.Parent = player.Backpack
secondaryClone.Parent = player.Backpack
else
warn("Something went wrong!")
end
end)
I will try figuring something out for like 10 more minutes and then,I will just sleep thru it and tomorrow mayby I will have an idea how to fix it or someone else will have an idea what to try.
To summorize
if HasTag criteria is meet the tool does not destroy itself;
Upon returning the for loop the script doesnt grant any weapons to the player
Pretty sure the tool was removed, as after it followed your print()
thing and it printed.
Re-check your text.
The quote of mine shows a script that destroys a tool using :Destroy() that means :Destroy() on tool works.
Another of your scripts is adding it back, without this context nobody can help you.
Maybe it’s even in StarterPack or StarterGear from where the other Tools are coming from.
I don’t think thats the case. I changed the HasTag to if tool.Name == “P90”
Now the tool is gone from my inventory so there can’t be a script adding it back.
As you can see the P90 is gone
RefreshArsenalEvent.Event:Connect(function(player, Weapon)
local inventory = player.Backpack:GetChildren()--
print(inventory)
for a, tool in pairs(inventory) do
print(tostring(tool))
if tool.Name == "P90" then
tool:Destroy()
end
end--[[
print(inventory)
local primaryWeapon = ServerStorage:FindFirstChild(player:WaitForChild("Database"):WaitForChild("PrimaryWeaponData").Value)
local secondaryWeapon = ServerStorage:FindFirstChild(player:WaitForChild("Database"):WaitForChild("SecondaryWeaponData").Value)
if primaryWeapon and secondaryWeapon then
local primaryClone = primaryWeapon:Clone()
local secondaryClone = secondaryWeapon:Clone()
primaryClone.Parent = player.Backpack
secondaryClone.Parent = player.Backpack
print(inventory)
else
warn("Something went wrong!")
end]]
end)
It can’t be the case.
Well, could you suggest to me any other way how to check is a weapon a weapon? Other one which doesn’t include CollectionService?
Make an attribution Weapon, then check if it has that attribution
I heard that having a lot of attributes lag the game, doesn’t it?
I don’t think so? I would assume only having it on weapons wouldn’t cost that much
Well, having 30 weapons in game. Each player has 2 weapons in their inventory. Lets say there is 15 combatants in game each one having different set of weapons.
But alright. I will do the attributes way
If it causes noticeable lag get a string value and put it in the tool and name it weapon, or just anything that sets the weapons different from anything else, and just check for that
My friend just replied to me with a solution noone suggested.
Instead of using :Destroy()
to use Debris
I have edited the for loop
in to following
for a, tool in pairs(inventory) do
print(tostring(tool))
if CS:HasTag(tool, "Weapon") then
Debris:AddItem(tool, 0)
end
end
And now it works perfectly. Thank you everyone for help and support.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.