I am creating a script to delete all items from a player’s StarterGear/ Backpack. The reason why I
want to do this is, for one, I have a Pay-to-Get-In ‘Healing Room.’ You need it so you don’t die and
lose your items. And two: A shop in my game brings a tool to the players StarterGear whenever
you buy something. (I tried changing it to the “Backpack,” but it never worked. And even then,
you’ll still spawn with it after death.)
Where I’m at now:
I currently have a Local Script inside of StarterPlayerScripts that is supposed to delete the items. Before I show you the script, there are three issues I already know. One: The script runs on a “While Wait() Do” statement, Looping the script even after the player respawns. Two: I’ve tried taking out the loop factor of the script, but it only worked once, Meaning it worked the first time a player died but not after. And three: I am not an expert coder by any means, so it’s all skin and bones. Okay, here’s the script:
local char = game.Workspace:WaitForChild(player.Name)
local hum = char.Humanoid
hum.Died:Connect(function()
while wait() do
for i, v in ipairs(script.Parent:GetChildren()) do
if v:IsA("Tool") then
v:Destroy()
end
end
for i, v in ipairs(player.Backpack:GetChildren()) do
if v:IsA("Tool") then
v:Destroy()
break
else --<<
for i, v in ipairs(script.Parent:GetChildren()) do
if v:IsA("Tool") then
v:Destroy()
end
end
for i, v in ipairs(player.Backpack:GetChildren()) do
if v:IsA("Tool") then
v:Destroy()
end
end
end
end
end
end)
when the player dies the backpack is already cleared so only the StarterGear needs to get deleted, right?
(server script btw)
game.Players.PlayerAdded:Connect(function(player)
local character = player.CharacterAdded:Wait()
local hum = character:WaitForChild('Humanoid')
hum.Died:Connect(function()
for i, v in pairs(player.StarterGear:GetChildren()) do
if v:IsA('Tool') then
v:Destroy()
end
end
end)
end)
Yes, because if the loop is removed, that is the only thing remaining. Now, with the loop, it does delete those items, but you can’t buy anything anymore…
This is weird, are there any scripts interfering? And are you sure the shop gives it in the first place, you should add prints when the for i,v destroys smth to see if its really the problem