Hello, I’m in process of making an equipment giver for security in my roleplay game.
The issue I’m having is the item won’t remove itself from player inventory upon calling an update event. Not sure why is that happening but player inventory stays the same and the inventory does not change the weapons. From the other hand the code above it works just fine. Each time you respawn it will spawn you with selected gun even if it didn’t give you it after interacting with a button (RefreshArsenalEvent)
Server Script
local ServerStorage = game:GetService("ServerStorage")
local Teams = game:GetService("Teams")
local RefreshArsenalEvent = game:GetService("ReplicatedStorage"):WaitForChild("Events"):WaitForChild("RefreshArsenal")
game.Players.PlayerAdded:Connect(function(player)
warn("Player!")
player.CharacterAdded:Connect(function(character)
warn("Character!")
if player.Team == Teams["Security Department"] or player.Team == Teams["Mobile Task Forces"] then
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
end
end
end)
end)
RefreshArsenalEvent.Event:Connect(function(player, Weapon)
local inventory = player.Backpack:GetChildren()
print(inventory)
for _, a in pairs(inventory) do
if a:HasTag("Weapon") then
a:Destroy()
print("Removed: ".. tostring(a))
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
end
end)
Data1 is P90 so player should switch MP7 with P90.
If you’re destroying the tool in a player’s backpack, you have to do it on the Client. Try firing back to the RemoteEvent with something like “DestroyTool” then in a localscript you can write
RefreshArsenalEvent.OnServerEvent:Connect(function(string, currentTool)
if string == "DestroyTool" then
currentTool:Destroy()
end
end)
You may be on to something, after adding or a.Name == "MP7" it did remove MP7, just not the secondary which had the weapon tag. Is there a chance that HasTag() may interrupt functionality? as after checking it by name it did remove the item sucessfully
If it’s going to be a free community resource, you could always release your current project as an alpha/beta version and have others send back the fixed bug(s).
Im sure other people wouldn’t mind helping out on it more directly if given credit for it.
task.wait(15)
print("Firing")
for _,player in ipairs(game.Players:GetPlayers()) do
for i,v in ipairs(player.Backpack:GetChildren()) do
if (v:HasTag("A_Tag!!!")) then
v:Destroy()
end
end
end
And the server removed the tool. So :Destroy() does destroy a tool.
Make sure the Tag is on the Tool and not the things inside the Tool, obviously it won’t remove that what you want.
If that doesn’t work, maybe it worked and did remove it, but maybe some other script that you have that we do not know about, is adding the same tool back?
I have been developing this game since around 2019/2020 and I have been improving it all of the time. It is a really large studio project which got scrapped multiple times and sometimes even copied with Synapse X and posted so I had to take it down.
If the only way for me to get this issue fix is publishing my project to the community which I spend countless hundreds of hours for I rather figuring out another way.