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

This scipt does the function once and then there is error, why?

local newRegion = Region3.new((Vector3.new(1,1,1)),(Vector3.new(10,10,10)))
local newPart = Instance.new("Part",workspace)
newPart.Anchored = true
newPart.Size = newRegion.Size
newPart.CanCollide = false
newPart.Transparency = 0.5
local partsInRegion  = workspace:FindPartsInRegion3(newRegion)


function test(pos)
	print(CFrame.new(Vector3.new(pos)))
	newRegion.CFrame = CFrame.new(pos)
	newPart.CFrame = newRegion.CFrame
	wait(1)
end




while true do 
	for i , v in pairs(game.Players:GetChildren())do
		if v ~= nil then
		local playerPos = v.Character:FindFirstChild("UpperTorso").CFrame
		if playerPos ~= nil then
			spawn(function()
				test(playerPos)
			end)
			end
		end
	end
	wait(1)
end

4 comments

0

where is the error

0

I have updated the script and the error i get is ServerScriptService.Main:12: bad argument #1 to 'new' (Vector3 expected, got CFrame)

0

ohhhhhh it has to be UpperTorso.Position not UpperTorso.CFrame, CFrame takes a Vector3 in the way you're using it

0

Too lazy to write an answer on mobile, but basically replace the "CFrame.new(pos)" with just "pos" (w/out quotes) on line 12, since it's already a CFrame.

1 answer

✓ Accepted answer

First of all, you cant assign a new cframe to a region3, you have to make a new one each time and you also can't make a cframe out of a cframe, you need the position. So im going to go ahead and plug my function in, so that it may create a new region3 out of a cframe and a vector3 size.

function GetMaxMinCorners(cframe,size)
	local min = {}
	local max = {}
	local size = size/2
	local corn = {}
	for x = -1, 1, 2 do
		for y = -1, 1, 2 do
			for z = -1, 1, 2 do
				table.insert(corn, (cframe * CFrame.new(size * Vector3.new(x, y, z))).p)
			end
		end
	end
	for i,v in next,{Enum.NormalId.Right, Enum.NormalId.Top, Enum.NormalId.Back} do
		local norm = Vector3.FromNormalId(v)
		table.sort(corn, function(a, b) return a:Dot(norm) > b:Dot(norm) end)
		table.insert(min, corn[#corn])
		table.insert(max, corn[1])
	end;
	min, max = Vector3.new(min[1].x, min[2].y, min[3].z), Vector3.new(max[1].x, max[2].y, max[3].z)
	return {["Min"] = min, ["Max"] = max}
end
local newRegion = Region3.new((Vector3.new(1,1,1)),(Vector3.new(10,10,10)))
local size1 = newRegion.Size
local newPart = Instance.new("Part",workspace)
newPart.Anchored = true
newPart.Size = newRegion.Size
newPart.CanCollide = false
newPart.Transparency = 0.5
local partsInRegion  = workspace:FindPartsInRegion3(newRegion)


function test(pos)
    local cf = CFrame.new(pos)
	local corners = GetMaxMinCorners(cf,size1)
    newRegion = Region3.new(corners["Min"],corners["Max"])
    newPart.CFrame = newRegion.CFrame
    wait(1)
end




while true do 
    for i , v in pairs(game.Players:GetChildren())do
        if v ~= nil then
        local playerPos = v.Character:FindFirstChild("Torso").Position
        if playerPos ~= nil then
            spawn(function()
                test(playerPos)
            end)
            end
        end
    end
    wait(1)
end


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