So, Ive been working on this script, that loops trough all the tools in the player’s backpack, copies the tools and then moves them to the player when he dies, the issue im having here is that my script changes the name of the part when it is cloned, for example, if the player had a sword in his inventory, it would clone it, rename it “Stolen sword” and move it to the player position when he dies, it works perfectly… But the issue here is that all it does is add “Stolen” to the name of the item, wich means if a player is carrying a item like a “Stolen sword” and dies with it, the sword will be renamed to “Stolen Stolen Sword”.
Does anybody know how i can fix this, is there something that i could use to check if the item already has “Stolen” in its name
Here’s the code, sorry if its messy
local char = script.Parent
local plr = game.Players:GetPlayerFromCharacter(char)
local hum = char:FindFirstChild("Humanoid")
local event = game.ReplicatedStorage.PlayerDied
hum.Died:Connect(function()
local Cfra = char.HumanoidRootPart.CFrame
event:FireClient(plr)
pack = plr.Backpack:GetChildren()
print("the player has "..#pack.." items in their inventory")
for i, v in pairs(pack) do
itemDropped = false
if itemDropped == true then
print("Item was already dropped, lets not duplicate")
elseif itemDropped == false then
itemDropped = true
print("item wasn't dropped, drop it")
local klon = v:Clone()
klon.Parent = workspace
klon.Name = "Stolen "..v.Name
klon.Handle.CFrame = Cfra + Vector3.new(0,10,0)
end
end
end)