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

Error Message: ')' expected near ',' on line 2?

I asked for some help before on how to make frames impossible to pass through but I will explain what I did anyways. (it worked but one piece of code didn't work for some reason) I made a controllable ImageLabel that the players can use WASD to control the ImageLabel. I've added an extra line of code that takes the Frame's position and subtracts with the ImageLabel's X position so players cannot pass beyond that point. Here is the code if needed:

if script.Down.Value == true and (position2.Position.Y.Scale + .0025) < 
	(0.168, 0,0.01, 0) - (0.017, 0)
		position2.Position = position2.Position + UDim2.new(0,0,0.0025,0)
	end

3 answers

Im not very good at this area of Roblox Lua but maybe this will work? What I changed:

(0.168, 0,0.01, 0) = (0.168, 0,0.01, 0) -- on line 2. i added the stuff after = 

the

then

is also required right there.

Final Code:

if script.Down.Value == true and (position2.Position.Y.Scale + .0025) < 
    (0.168, 0,0.01, 0) = (0.168, 0,0.01, 0) - (0.017, 0) then
        position2.Position = position2.Position + UDim2.new(0,0,0.0025,0)
    end

Please accept if this solves it! Hope this works.

1 comment

0

im very sorry to say this but it does not work. :(

The problem is not your if statement. It's your math.

Look at line 2:

(0.168, 0,0.01, 0) - (0.017, 0)

Putting commas there tells Lua that it is a tuple, not a number. That's why you're getting an error.

In this case, I can only assume you're trying to compare matrices. There are some rules that must be learned here:

  • You cannot perform math on matrices that have a differing number of values. For example, you can't subtract a Vector2 from a Vector3 because they're not the same matrix. Vector2 values are 3x1 matrices while Vector3 values are 4x1 matrices.

That rule also applies with UDim2 values.

Even then, your code would look like this on line 2:

UDim2.new(0.168, 0, 0.01, 0) - Vector2.new(0.017, 0) -- This is obviously incorrect

So, how do you fix the problem? You can make both "tuples" set values by wrapping constructor functions around them (they must have the same number of values and they must be the same constructor, with the exception of CFrame and Vector3). If you don't want to do that, you can subtract the numbers separately.

1 comment

0

I was trying to subtract a Frame's size and an ImageLabel's X scale size.

Isn't that great? I got a new error :P

wait(0.1)
local runservice = game:GetService("RunService")
local position2 = game.Players.LocalPlayer.PlayerGui.battle.black.heart
runservice.RenderStepped:connect(function()
	if script.Up.Value == true then
		position2.Position = position2.Position + UDim2.new(0,0,-0.0025,0)
	end
	if script.Down.Value == true and (position2.Position.Y.Scale + .0025) < UDim2.new(0.168,0.01) - UDim2.new(0.017, 0) then
	    position2.Position = position2.Position + UDim2.new(0,0,0.0025,0)
	end
	if script.Right.Value == true then
		position2.Position = position2.Position + UDim2.new(0.0025,0,0,0)
	end
	if script.Left.Value == true and (position2.Position.X.Scale - .0025) > 0 then 
		position2.Position = position2.Position + UDim2.new(-0.0025,0,0,0)
	end
end)

1 comment

0

11:45:24.458 - Players.p0vd.PlayerGui.Cam:8: attempt to compare number with userdata

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