I got the error The Parent property of WhiteBox is locked, current parent: NULL, new parent Torso

This script is supposed to put into and weld an object called WhiteBox into player’s torso. Upon entering it works as it should, but when player dies this error appears (and WhiteBox doesn’t get putted into torso). halp

local whitebox = game.ReplicatedStorage.WhiteBox
Players = game:GetService("Players")
RunService =game:GetService("RunService")
Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local weld = Instance.new("WeldConstraint")
		weld.Parent = character.Torso
		whitebox:Clone()
		whitebox.Parent = character.Torso
		local WB = character.Torso.WhiteBox
		local Torso = character.Torso
		weld.Part0 = Torso
		weld.Part1 = WB
	
	end)
	end)
1 Like

Uncheck the property “locked” of whitebox in ReplicatedStorage

1 Like

On the cloning part, try localizing it and parent to the character’s torso.
Here’s what it should look like:

local whitebox = game.ReplicatedStorage.WhiteBox
Players = game:GetService("Players")
RunService =game:GetService("RunService")
Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local weld = Instance.new("WeldConstraint")
		weld.Parent = character.Torso
		local newBox = whitebox:Clone()
		newBox.Parent = character.Torso
		local WB = character.Torso.WhiteBox
		local Torso = character.Torso
		weld.Part0 = Torso
		weld.Part1 = WB
	end)
end)
3 Likes

Thank you!!!
(i added more exclamation marks cuz of character limit)

1 Like
local repstorage = game:GetService("ReplicatedStorage")
local whitebox = repstorage:WaitForChild("WhiteBox")
local players = game:GetService("Players")
local runService =game:GetService("RunService")

players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local weld = Instance.new("WeldConstraint")
		local torso = character:WaitForChild("Torso")
		weld.Parent = torso
		local whiteboxClone = whitebox:Clone()
		whiteboxClone.Parent = torso
		weld.Part0 = torso
		weld.Part1 = whiteboxClone
	end)
end)

This is cleaner, I’ve removed unnecessary declarations, such as “WB” as it already exists as “whitebox” in your script. I’ve also added waits to prevent the script trying to execute before required instances have loaded. But yeah, your issue was that you were cloning the whitebox but not assigning it anywhere, so where you next parented the whitebox you were parenting the original whitebox and not the clone.

2 Likes

Uh uh, my dude, WB is important, cuz for some reason if there’s more than 1 players in a game one player gets attached to another
but thanks anyway

local WB = character.Torso.WhiteBox
local whiteboxClone = whitebox:Clone()

These are both referencing exactly the same instance, the clone of the whitebox, so no it isn’t necessary to declare a variable twice for the same instance. A clone is made for each player’s character every time they respawn. Try to go through the logic in my code & you’ll understand.

local whitebox = whitebox:Clone()
whitebox.Parent = character.Torso
local WB = character.Torso.WhiteBox

Notice how whitebox and WB are referencing the same instance? This is your script with the fix Zach added (assigning the clone to a variable).

Also it’s better to declare variables locally, in your original script you had declared “Players” as a global, declaring variables locally makes them part of the local environment and as such they can be accessed quicker.

Huh, okay, I can see it now. .