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

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

Asked by 9 years ago

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

Log in to vote
2
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
9 years ago

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)
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? rex1234551 0 — 9y
0
The TextButton variable I just made up. You need to specify what it's really supposed to be referring to. 1waffle1 2908 — 9y
Ad

Answer this question