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

What did I do wrong in this value checker and adder script?

Asked by 7 years ago
Edited 7 years ago

In my script, I was trying to do something like this: So if you press "T" the script will check the value of a value, if the value is 0 it will proceed but if the value is 1 it will reset and will not do the rest. The rest of the script adds to the value, so like I said before if the value is 0 it would proceed, meaning it will change the value to 1.

function onKeyPress(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.T then
        if game.Workspace.Tsundere.Value == 1 then
            game.Workspace.Tsundere.Value = 0
        else
        game.Workspace.Tsundere.Value = (game.Workspace.Tsundere.Value +1)
    end
end
game:GetService("UserInputService").InputBegan:connect(onKeyPress)

1 answer

Log in to vote
0
Answered by 7 years ago

I'm not sure but I can help you edit your script and it may work, there are ways to help you improve that script;

local uis = game:GetService("UserInputService") --Make a variable instead
local T = game.Workspace:WaitForChild('Tsundere') --Make variable and use WaitForChild to wait for it to load in first

uis.InputBegan:Connect(function(Input)
    if Input.KeyCode == Enum.KeyCode.T then
        if T.Value == 1 then
            T.Value = 0
            if T.Value == 0 then
                T.Value = 1
            end
        end
    end
end)

This is much easier and simple to understand. I might have a made a mistake in the code but you can fix it. \ NOTES:

  1. Make sure this is a LocalScript Inside of StarterPlayerScripts
  2. Make sure Tsundere's Value is actually 1
  3. IF It still doesn't work try adding prints to find problems
  4. Make sure all the conditions are met

Anyway if I was able to help then please accept answer.

Good luck developing!

Ad

Answer this question