Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why cant i compare the different texts?

Asked by 5 years ago

im trying to make a set speed box and compare the text inside it with another text that holds my speed but it doesnt work why? local script:

if not script.Parent.Text > script.Parent.Parent.jump.Text then

game.Players.LocalPlayer.Character.Humanoid.JumpPower = script.Parent.Text

end

error: 17:18:54.828 - Players.world_kiIIer.PlayerGui.ScreenGui.speed.speed:1: attempt to compare string with boolean

17:18:54.828 - Stack Begin

17:18:54.829 - Script 'Players.world_kiIIer.PlayerGui.ScreenGui.speed.speed', Line 1

17:18:54.829 - Stack End idk what that means

1 answer

Log in to vote
0
Answered by
Vik954 48
5 years ago
Edited 5 years ago

I think that in this text box you want to enter an Number, but the Text property holds a String. To transform the String into a Number you need the tonumber() function. This way, you can compare these two.

You can also ensure your safety in the code by instead of writing not script.Parent.Text > script.Parent.Parent.jump.Text, you would write not (script.Parent.Text > script.Parent.Parent.jump.Text), so it looks at the result, not at one of the numbers.

0
i tried with tonumber and the brackets but it still dont work, now i got the error " p, li { white-space: pre-wrap; } attempt to compare nil with boolean" Gameplayer365247v2 1055 — 5y
0
Interesting, but i think that the "not" comand can be replaced. if a number is not greater than another number it is equal or smaller than that number, so we can write "tonumber(script.Parent.Text) <= tonumber(script.Parent.Parent.jump.Text)" Vik954 48 — 5y
Ad

Answer this question