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

Which is this line of code working in a way, but not in the other?

So this specific line of code is making the value not go over 180 which is correct, but the adding function to get to 180 when it goes over 2 it changes to 180. So basically it works as in not allowing the value to go over 180, but it doesn't let u do it by 1s which is the adding functions and the way its suppose to be done.

No output errors.

Plus.MouseButton1Click:Connect(function() 
	Number.Text = Number.Text + 1
PlusExample.Text = 180
if Number.Text > PlusExample.Text then Number.Text = 180
	end
end)

2 answers

✓ Accepted answer

The first thing which is making me worried when looking at your script, is that you're trying to compare a strings with each other. Anything . I highly encourage you to convert the values into to numbers before doing a comparison.

-- How to convert a string into a number
local number = tonumber('100')




-- Whenever you try to compare strings with each other, you'll always end up with the same result.
local text1 = 'Hello'
local text2 = 'World'

-- The following results will always return the same, even if you change the variables content.

if (text1 > text2) then -- will return false
	
end

if (text1 < text2) then -- will return true
	
end
Plus.MouseButton1Click:Connect(function() 
 Example.Text = 180
 if Number.Text < Example.Text then 
  Number.Text = Number.Text + 1
 end
end)

Try it like this, it says that if the Example.Text value is lesser than 180 then it will add +1 but if it isnt lesser than 180 it will do nothing

11 comments

0

That makes it a string compared to a number which doesn't work

0

Ew, then i think Example.Text = 180 will work, or you could replace Example.Text at line 3 for 180

0

It solves that problem, but it still doesn't let it go above 2

0

Is there some other script affecting this value?

0

Not that i know of

0

I did some tests and it seems to work fine for me, i added a print(Number.Text) in the function and it is adding up to 180 without any issues, i guess something in your game could be making this issue, could you say what are you using this script for?

0

Yes a gui for seat recline

0

What is the 180 for?Is it the seat angle dregree?

0

Yes

0

So i spawned in a new baseplate and tried the script with a basic gui i made and i still have the same problem

0

Could you share the script via pastebin?Maybe the issue is in the CFrame adding, i made some test with CFrame adding and nothing gone wrong.

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