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

What is this error, and how do I fix it?

I am making a plugin that creates walls along the edges of the selected part, but it keeps coming out with this error:

08:10:43.551 - Plugin_191344304.MakeWalls.Script:50: bad argument #1 to '?' (Vector3 expected, got number)
08:10:43.552 - Script 'Plugin_191344304.MakeWalls.Script', Line 50
08:10:43.552 - Stack End
08:10:43.553 - Disconnected event because of exception

The code is here:

local pluginVersion = 0.35
local hasLoaded = plugin:GetSetting("pluginHasLoaded")
print("Loading ExplosionCreate Plugin v" .. pluginVersion) --Just a loading message
if not hasLoaded then
	plugin:SetSetting("pluginHasLoaded", true)
end
 
-- Setup Toolbar
local toolbar = plugin:CreateToolbar("dudemanloserr Productions") --Toolbar Name
local isActive = false
-- Setup button
local button = toolbar:CreateButton(
	"MakeWalls", -- Button Text
	"MakeWalls Plugin: Click a part to create 3-stud-tall walls, of the same color, along it's edges.", --Text that appears when you hover over the button with the mouse
	"9869681" -- Button Icon ID
)
button.Click:connect(function() -- When the plugin button is clicked, do this stuff.
	if isActive == false then
		plugin:Activate(true)
		isActive = true
	elseif isActive == true then
		plugin:Activate(false)
		isActive = false
	end
end)
 
--MouseButton1(left mouse) function
local mouse = plugin:GetMouse()
mouse.Button1Down:connect(function()
	if isActive then
		local targ = mouse.Target
		local wallsMade = 0 -- Amount of walls made
		while wallsMade < 4 do --Nobody likes For loops, right?
			local wall = Instance.new("Part", targ.Parent)
			wall.Name = "WallPart"
			wall.BrickColor = targ.BrickColor
			--Code from here going down makes the walls surfaces the same as the target's
			wall.BackSurface = targ.BackSurface
			wall.BottomSurface = targ.BottomSurface
			wall.FrontSurface = targ.FrontSurface
			wall.LeftSurface = targ.LeftSurface
			wall.RightSurface = targ.RightSurface
			wall.TopSurface = targ.TopSurface
			--The surfaces should be the same by this point.
			local x = targ.Position.X-targ.Size.X/2
       			local y = targ.Position.Y+targ.Size/2       -- (LINE 50)
			local z = targ.Position.Z
			if wallsMade == 0 then --Negative X
				wall.Position = Vector3.new(x, y, z)
				wall.Size = Vector3.new(targ.Size.X, 3, 1)
			elseif wallsMade == 1 then
				x = targ.Position.X
				z = targ.Position.Z-targ.Size.Z/2
				wall.Position = Vector3.new(x, y, z) --Negative Z
				wall.Size = Vector3.new(1, 3, targ.Size.Z)
			elseif wallsMade == 2 then
				x = targ.Position.X+targ.Size.X/2
				z = targ.Position.Z
				wall.Position = Vector3.new(x,y,z) --Positive X
				wall.Size = Vector3.new(targ.Size.X, 3, 1)
			elseif wallsMade == 3 then
				x = targ.Position.X
				z = targ.Position.Z+targ.Size/2
				wall.Position = Vector3.new(x,y,z) --Positive Z
				wall.Size = Vector3.new(1, 3, targ.Size.Z)
			end
			wallsMade = wallsMade + 1
		end
	end
end)
print("Loaded WallsPlug Plugin v" .. pluginVersion) --Another loading message

1 answer

Ah, I see what the issue is here.

local y = targ.Position.Y+targ.Size/2

You're either setting y to a number or a Vector3. As you can see, at first, you're setting Y to a number because you put targ.Position.Y, and the Y position is a number. THEN, you're trying to get the ENTIRE size of the targ, which returns a Vector3 value, and dividing it by two.

A solution? Well, there's two ways. You can either set Y to a number (recommended), or set Y to a Vector3.

Y to a number (recommended): NOTE: I am really unsure of what you are trying to do right here. From what you're doing with the x variable, it looks like you want to do this.

local y = targ.Position.Y + targ.Size.Y / 2

I am doing this because the X variable is set to local x = targ.Position.X - targ.Size.X / 2.

Hope this helps!

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