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

How can I make these numbers appear on a text button?

I have a rather simple code that I need to be displayed into a text button, this is it so far.

number = 164 while number >164 or <2404 if pressing w then...number=number +32 elseif pressing s then number =number -32

I need the numbers to change and be displayed in a text button.

1 answer

You want to use the InputBegan and InputEnded events of UserInputService to tell when keys are being pressed and a TextButton object to display a number in a text button.

A number that is either greater than 164 or less than 2404 is every number.

local number=164
local TextButton=Instance.new("TextButton",Instance.new("ScreenGui",game.Players.LocalPlayer:WaitForChild("PlayerGui")))
TextButton.Text=number

local inputservice=game:GetService("UserInputService")
local wdown,sdown=false,false
inputservice.InputBegan:connect(function(input)
	if input.KeyCode.Name=="W"then
		wdown=true
		while wdown do
			wait(.1)
			number=number+32
			TextButton.Text=number
		end
	elseif input.KeyCode.Name=="S"then
		sdown=true
		while sdown do
			wait(.1)
			number=number-32
			TextButton.Text=number
		end
	end
end)
inputservice.InputEnded:connect(function(input)
	if input.KeyCode.Name=="W"then
		wdown=false
	elseif input.KeyCode.Name=="S"then
		sdown=false
	end
end)

2 comments

0

I'm having a problem with the script, I have tried to put the script you've provided into the area that it is needed, but It's not working, Right now it's formatted like this: https://gyazo.com/464019099e76b569b298bb234024c954 Do you know how to fix this?

0

The TextButton variable I just made up. You need to specify what it's really supposed to be referring to.

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