Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Unable to cast value to object? [Solved]

This error just recently appeared and I have no idea what it means. The error is on line 10. Note; script.Parent is not the workspace. I'm putting the bleft and tright parts inside the scripts parent as I will use a different position of bleft and tright for every copy of the script's parent.

Server script:

local bleft = script.Parent.bleft.Position
local tright = script.Parent.tright.Position

local region = Region3.new(
	Vector3.new(math.min(bleft.X, tright.X), math.min(bleft.Y, tright.Y), math.min(bleft.Z, tright.Z)),
	Vector3.new(math.max(bleft.X, tright.X), math.max(bleft.Y, tright.Y), math.max(bleft.Z, tright.Z))
) -- math.min & max to prevent issues with Region3

while wait() do
	for i, part in pairs(workspace:FindPartsInRegion3WithIgnoreList(region, {bleft, tright, script.Parent})) do
		local player = game.Players:GetPlayerFromCharacter(part.Parent)
		
		if player then
			if not player.Transfurmed.Value then -- If player is not transfurmed
				print('Initiate transfurmation')
				
				player.Transfurmed.Value = true -- To clarify that player is transfurmed to not initiate transfurmation on a transfurmed player
				game.ReplicatedStorage.GiveAbilityToTransfurm:FireClient(player)
				
				player.Character.Shirt:Destroy()
				player.Character.Pants:Destroy() -- To turn whole character to color
			end
		end
	end
end

1 answer

Nevermind, I forgot i set the bleft and tright to their respective positions, not the objects themselves.

The solution here is to reference them indiviually.

This discussion is preserved as it was. New answers, comments, and votes are closed.