Keepinventory upon refreshing [Solved]

I’m currently working on a prison game where when a person escapes and gets to a certain base there is a dummy where you can wear your own clothing again. Now i need that the player keeps their inventory when they do that. The current script is the following:

script.Parent.Triggered:Connect(function(player)
	local cframe = player.Character.HumanoidRootPart.CFrame
	local backpack = player.Backpack:GetChildren()
	backpack.Parent = script.Parent.BagpackRefresh
	player:LoadCharacter()
	wait()
	player.Character.HumanoidRootPart.CFrame = cframe
	backpack.Parent = player.Backpack
end)
1 Like

This script might be incorrect, so please notify me if it is! :sweat_smile:

Basically, what has gone wrong in your script is that you didn’t specify exactly which Child in player.Backpack:GetChildren() you want to move to script.Parent.BagpackRefresh. So, Studio throws an error.

local savedBackpack = script.Parent.BagpackRefresh

script.Parent.Triggered:Connect(function(player)
  local cframe = player.Character.HumanoidRootPart.CFrame
  local backpack = player.Backpack:GetChildren()
  for i, items in pairs(backpack) do
   items.Parent = savedBackpack
  end
  player:LoadCharacter()
  wait()
  player.Character.HumanoidRootPart.CFrame = cframe
  for i, items in pairs(savedBackpack:GetChildren()) do
   items.Parent = player.Backpack
  end
 end)
1 Like

the only problem was that i had to move “BagpackRefresh” to ReplicatedStorage. Thank you.

1 Like

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