# How to stop needing to copy n paste this over and over

i want to make a “type your walkspeed number” and what i do is copy n paste this:
TexasButton.MouseButton1Click:Connect(function()

``````if TextBox.Text == "5" then
if h.WalkSpeed == 5 then
h.WalkSpeed = 16
else
h.WalkSpeed = 5

end

end
``````

end)

but i dont want to do that over and over until 100
how will i do that?

1 Like
``````if h.WalkSpeed == DEFAULT_WALKSPEED then
h.WalkSpeed = tonumber(textBox.Text)
end
``````

?

1 Like

plz explain (plz explain i dont understand where u get tonumber from)

this is what i think u mean
if h.WalkSpeed = 16 then
h.WalkSpeed = 100(TextBox.Text)

``````TexasButton.MouseButton1Click:Connect(function()
if TextBox.Text == "5" then
if h.WalkSpeed == 5 then
h.WalkSpeed = 16
else
h.WalkSpeed = 5
end
end
end)
``````

Convert the TextBox text to a number and just use the number where you would use 5 in this script.

2 Likes

It’s a built in function. Check out this page for more: Lua Globals | Roblox Creator Documentation

1 Like

but how will you know the tonumber? will you need to make a variable?
edit: when i went through i saw 1. print(tonumber(“1337”)) → 1337 (assumes base 10, decimal)
so you will need to do
h.WalkSpeed = tonumber(100)(textBox.Text)?

Nope, it’s a “global” variable, meaning all parts of every script can access it. Just try this simple script to see what I mean:

print(tonumber(“100123123”))

1 Like

is this correct?

TexasButton.MouseButton1Click:Connect(function()

``````if TextBox.Text == tonumber(1000) then
if h.WalkSpeed == tonumber(1000) then
h.WalkSpeed = 16
else
h.WalkSpeed = tonumber(1000)

end

end
``````

end)

Why not just do

``````if tonumber(TextBox.Text) > 5 or tonumber(TextBox.Text) < 100 then
h.WalkSpeed = 16
else
h.WalkSpeed = 5
end
``````

bmy braincells are decreasing per second reading it
i dont understand 1st line
ohhh ok <— edit

It converts the text to a number so if the Text = 5 then instead of it being a string, it will be a number.

1 Like