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

Why cant i compare the different texts?

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

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.

2 comments

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"

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

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