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
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?
The TextButton variable I just made up. You need to specify what it's really supposed to be referring to.