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

Can you help me with this script?

Asked by 8 years ago
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)

`

It's designed to make a Text button display a number every time an s or w key is pressed, but I cannot make the script work with the button, can you help fix this?

0
is this script a LocalScript TheDeadlyPanther 2460 — 8y

2 answers

Log in to vote
0
Answered by
qwrn12 85
8 years ago

i found it when you did

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

the if input.KeyCode.Name=="W"then should be if inputObject.KeyCode.Name=="W"then you forgot inputObject

Ad
Log in to vote
0
Answered by
Wutras 294 Moderation Voter
8 years ago

I'm not sure about this one, but I think that the problem with this is that you used a number value in a string value. If this is not the problem and the code is put into a normal Script, just change it to a LocalScript like TheDeadlyPanther said.

This would be the solution:

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

I'm neither sure about whether it will work nor have I tested it, but I still hope it helps you. :)

0
Sorry, neither of these have helped me. rex1234551 0 — 8y
0
Could you send a screenshot of the output? Wutras 294 — 8y

Answer this question