Error: The Parent property of SWORD is locked, current parent: NULL, new parent Backpack

You can write your topic however you want, but you need to answer these questions:
I wanted to make a backpack UI that replaced the roblox one. But, I got an issue with the tools parent after i die once. It works the first time, but after they die, they can not take out the sword again. Here is my local script.

local rep_storage = game.ReplicatedStorage
local inventory = rep_storage.ui.inventory
local get_inventory = inventory.inventory
local equip_status = inventory.equip
local local_player = game.Players.LocalPlayer
local user_input_service = game:GetService("UserInputService")
local tween_service = game:GetService("TweenService")

game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,false)

wait(1)

local ui = Instance.new("ScreenGui")
ui.ResetOnSpawn = false
ui.Name = "inventory"
ui.Parent = local_player.PlayerGui

local holder = inventory.holder:Clone()
holder.Name = 'holder'
holder.Parent = ui


local MAX = 1
local keybind = {
	
}

function check_Status()
	wait()
	if equip_status:InvokeServer(keybind["One"].item) == true then
		tween_service:Create(holder["SWORD"],TweenInfo.new(.25,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut,0,false,0),{ BackgroundColor3 = Color3.fromRGB(255,255,255) }):Play()
		tween_service:Create(holder["SWORD"].TextLabel,TweenInfo.new(.25,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut,0,false,0),{ TextColor3 = Color3.fromRGB(58,58,58) }):Play()
	else
		tween_service:Create(holder["SWORD"],TweenInfo.new(.25,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut,0,false,0),{ BackgroundColor3 = Color3.fromRGB(58,58,58) }):Play()
		tween_service:Create(holder["SWORD"].TextLabel,TweenInfo.new(.25,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut,0,false,0),{ TextColor3 = Color3.fromRGB(255,255,255) }):Play()
	end
end

for i , items in pairs(get_inventory:InvokeServer()) do
	if i <= MAX then
		local temp = inventory.temp:Clone()
		temp.Name = items.Name
		temp.TextLabel.Text = string.upper(items.Name)
		temp.Parent = holder
		
		keybind["One"] = { ["key"] = "One", item = items }
		
		temp.equip.MouseButton1Click:Connect(check_Status)
	end
end

user_input_service.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode[keybind["One"].key] then
		check_Status()
	end
end)

local_player.Character:WaitForChild("Humanoid").Died:Connect(function()
	keybind["One"].item = get_inventory:InvokeServer()[1]
end)

and this is my Server Script

local rep_storage = game.ReplicatedStorage
local inventory = rep_storage.ui.inventory
local get_inventory = inventory.inventory
local equip = inventory.equip

function get_player_inventory(plr)
	return plr.Backpack:GetChildren()
end

function equip_status(plr,item)
	if plr and plr.Backpack then
		if item.Parent ~= plr.Backpack then
			item.Parent = plr.Backpack
			return false
		else
			local char = plr.Character
			local hum = char:FindFirstChild("Humanoid")
			hum:EquipTool(item)
			return true
		end
	end
end

get_inventory.OnServerInvoke = get_player_inventory

equip.OnServerInvoke = equip_status
1 Like

Well, it works when the player has never died, but after they die then the error occurs

Adding a task.wait(.2) at the start of the LocalScript should work…

Nope, does not work but i think if i add the script in startercharacterscripts it might work better

lol, it works after i put it in the startercharacterscripts. Thank you guys for the help!

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