Changing .Parent of an object doesn't work when leaving

Goal:

I want to get the Obby map change it’s parent when a player that owns the map leaves, but things go wrong and here’s what I’ve got.


image

Script:


Players.PlayerRemoving:Connect(function(plr)
	local Obby = plr:WaitForChild("stats").Obby
	local Challenge = plr:WaitForChild("stats").Challenge 
	print("asdasd")
	if not workspace.Obbies:FindFirstChild(Obby) then
		workspace.Obbies:FindFirstChild(ObbyOwned(plr)).Parent = ServerStorage.Obbies
	end
end)

More information:


The script is server-sided, the ObbyOwned() script is:

local function ObbyOwned (player)
	return player:WaitForChild("stats").Obby.Value
end

Hopefully the function itself is fine, but when I did use Obby variable instead of that function, it would give the same error. Obby variable also stores the map’s name, I know there could be more ways to get that, but it’s the easiest and most efficient one i’ve got.
Thanks!

You are trying to Parent a Value and not the Instance itself.

When using this kind of module in other script, it works very fine, as I am trying to find the child by a name. It’s just this script that doesn’t work.