Delete all tools in inventory Apon death problem [SP]

The script is a normal script, not local. It’s in ServerscriptService

local replicatedStorage = game:GetService("ReplicatedStorage")
local shopItems = game:GetService("ServerStorage"):WaitForChild("ShopItems") -- Where tools are held

replicatedStorage.GetInfo.OnServerInvoke = function(player,item)
	return shopItems[item].Cash.Value
end


replicatedStorage.CheckSale.OnServerInvoke = function(player,item)
	
	local price = shopItems[item].Cash.Value
	
	if player.leaderstats.Cash.Value >= price then
		
		player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - price
		
		local gear = shopItems[item][item]:Clone()
		gear.Parent = player.StarterGear
		
		local gear = shopItems[item][item]:Clone()
		gear.Parent = player.Backpack
		
		return true
		
	else
		
		return false	
	
	end

	
	
end

game.Players.PlayerAdded:Connect(function(player)
	local charcter = player.Character or player.CharacterAdded:Wait()
	local humanoid :Humanoid = charcter:WaitForChild("Humanoid")
	
	humanoid.Died:Connect(function() -- I Used This Event To Avoid Deleting All The Tools When The Players Joins For The First Time Because I am using the CharacterAddded Event
		player.CharacterAdded:Connect(function(newCharcter) -- This Function Is Called When A Player Spawns For The First Time Or Respawns
			-- Very Important !!! We Wait For The Charcter To Load When The Player's Respawns
			repeat
				task.wait()
			until
			newCharcter

			for i , v in pairs(newCharcter:GetChildren()) do
				if v:IsA("Tool") then
					v:Destroy()
				end
			end

			for i , v in pairs(player.Backpack:GetChildren()) do
				if v:IsA("Tool") then
					v:Destroy()
				end
			end
		end)
	end)
end)

It’s a ServerScript

It still doesn’t work, even as a ServerScript

: /
Thanks for the suggestion though!

I might make a noncopylocked game with both elements in it for devs to screw with, because I genuinely don’t know…

So, since the script that gives you the items is a server script, it has to be the one in post maybe…

Sadly i dont know the problem anymore

I found that in the main script, it was cloned to the backpack and the StarterGear, so I removed it and it works now!

Thank you everyone for helping!

1 Like

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