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

Why is this function not being executed?

function changeSize(brick, size)
	workspace:FindFirstChild(brick).Size = Vector3
end

changeSize("Blue", 4,4,4)

2 answers

✓ Accepted answer

The problem here is because you aren't doing anything with Vector3. All you are doing is indexing the global table that is Vector3.

You need to define what you are doing, for example:

Vector3.new(0,0,0) -- creates a valid position

As well as that, when calling the function, what you are doing is creating 4 parameters, not 2. size would be equivalent to the first number you stuck into the function: 4.

To fix this, either define with x, y, z in your function's code, set the single parameter to a Vector3.new(), or use .... I will show examples of each.

-- EXAMPLE 1:

function changeSize(brick, x, y, z)
	-- part stuff
	part.Size = Vector3.new(x,y,z)
end

changeSize("Name", 1, 2, 3)
-- EXAMPLE 2:

function changeSize(brick, size)
	-- part stuff
	part.Size = size
end

changeSize("Name", Vector3.new(1,2,3))
-- EXAMPLE 3:

function changeSize(brick, ...) -- '...' basically means an infinite amount of undefined variables
	-- part stuff
	part.Size = Vector3.new(...) -- sticks the 'infinite undefined variables' into the vector3
end

changeSize("Name", 1, 2, 3) -- in this case, '...' is equal to 1, 2, 3

Hope I helped!

~TDP

2 comments

0

He is not indexing Vector3 at all. He is assigning the Size property of the part with name brick to the Vector3 table.

0

Index means in context: 'link the value of'. The value he is indexing in this case is Vector3, not it's values. Just to clear it up. 

A few reasons.. One, on the function parameters you only have 2 parameters so thus you are getting this "Blue", 4. Second, the Vector3 needs to be Vector3.new()

Let me point you in the direct path here.

function changeSize(brick, Table)
	local x,y,z = Table[1],Table[2],Table[3] -- Sorts all the supported data from the call
       local Brick = workspace:FindFirstChild(brick)
	if Brick then
		Brick.Size = Vector3.new(x,y,z)
	else
		warn("No brick")
	end
end

changeSize("Blue", {4,4,4})

If you have any problems with this script please let me know.

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