Assign a new sword every kill

So i want to assign a new sword to player everytime he kills someone and i tried to do it by having a tag for sword number 1 and so on and i made a variable that represenets which sword is the player going to get with :

local KillToSword = tostring(Kills.Value + 1)

And then doing this :

for _,v in pairs(CollectionService:GetTagged(KillToSword)) do
		v.Parent = player.Backpack

But this doesn’t work. Any help would be appreciated.
*Also please consider i am kind of a begginer

1 Like

Are there any errors in the output or is it possible for you show us the the entire script just in case something is missing?

Sadly there are no errors in the output :frowning:

Can you check if the swords are really tagged?

Another concern I have is that the sword’s Parent can be constantly switching between players due to this code:

because it refers to the sword itself, not a clone.
But even then, the clones would be tagged too and this code would retrieve every single sword with the tag.

I suggest you might have to not use tags. I have never used tags before so I could be really wrong about this.

Yeah, they are. For now i have only 2 tags just for testing.

check if the sword getting parented to player’s backpack

Thats actually very good idea, but still nothing happens. Maybe there could be a way to do it in local script, because i don’t want the swords to get saved or anything so it will probably be useless to have it in server script

Oh the sword is equal to nil. I could also loop trough the folder i have the swords in and call them 1 and so on and then just change their name that could be stored for example in a string value or table

so you have no sword tagged with the tag you finding it

I have, but still nothing. Rn i tried to do this, but it still doesnt work :
for _,v in pairs(game.ServerStorage.Weapons:GetChildren()) do
if v.Name == KillToSword then
v:Clone().Parent = player.Backpack

May I see a screenshot of where the sword folder is located, what is in it, and which sword is which tag?

Can you also please elaborate more on this? Do you mean “not letting the player still retain the sword in their backpack when they respawn” by it not getting saved?

Also please check if the sword is Archivable, and if swords are actually present during testing session or not.

I mean that when the player leaves he starts over, but when he dies he keeps them. Also the swords are archivable, but i just realised that the swords are present when i switch from client to server

ServerStorage doesn’t replicate to clients so you cannot see them on client-sided testing session, nor can LocalScripts access the storage. If the scripts are server-sided then it should’ve worked.

Did you try this code on the server or client? (I think you said server, but I’m asking just to be sure.)

It’s a server script that i’m using

This is really bizarre. No errors too? I think you might need to try printing children in the Weapons folder to see if the weapons are even there in the first place when testing, or if it is moved somewhere else. Otherwise, if you can, please try posting the entire script here.

Well nevermind i actually fixed it by using character added, because i was assigning the sword to character that wasnt even loaded yet

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.