0

# 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)


0
ScuffedAI 441
1 year ago
Edited 1 year ago

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

0
Edited 1 year ago
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

0
That makes it a string compared to a number which doesn't work preston1196 22 — 1y
0
Ew, then i think Example.Text = 180 will work, or you could replace Example.Text at line 3 for 180 kevinsoaresv 47 — 1y
0
It solves that problem, but it still doesn't let it go above 2 preston1196 22 — 1y
0
Is there some other script affecting this value? kevinsoaresv 47 — 1y
0
Not that i know of preston1196 22 — 1y
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? kevinsoaresv 47 — 1y
0
Yes a gui for seat recline preston1196 22 — 1y
0
What is the 180 for?Is it the seat angle dregree? kevinsoaresv 47 — 1y
0
Yes preston1196 22 — 1y
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 preston1196 22 — 1y
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. kevinsoaresv 47 — 1y