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

The Player is getting, +1 points, but then they get +3 then +6?

So when the players Press a Key, they get a point, then a countdown appears and a new Random Key is appeared, when players press that second random Key, they get **+3 points, ** when they press the Third Random key they get +6 Points, why?

local UIS = game:GetService("UserInputService")
local randomKey = workspace.Rooms.RoomOne.randomKey
local player = game.Players.LocalPlayer
local RoomOneTable = require(game.ReplicatedStorage.Rooms.RoomOne.RoomOneMod)
local restartRound = game.ReplicatedStorage.Rooms.RoomOne.restartRound
local defaultKey = game.ReplicatedStorage.Rooms.RoomOne.keyDefault -- set the random key to default
local canPressFalse = game.ReplicatedStorage.Rooms.RoomOne.canPressFalse
local canPress = workspace.Rooms.RoomOne.canPress

workspace.Rooms.RoomOne.randomKey.Changed:Connect(function()
    workspace.Rooms.RoomOne.newRound.Value = true
end)
while wait(1) do
    
if workspace.Rooms.RoomOne.newRound.Value == true then
    if player:FindFirstChild("thePointsOne") then
        UIS.InputBegan:Connect(function(key, whileTalking)
            if whileTalking then return end
        while wait() do
            if canPress.Value == true then
                -- if players can press
            if player.thePointsOne.Value == 5 then
                print("You won the game")
            else
                if key.KeyCode == Enum.KeyCode[randomKey.Value] then
                    print(player.Name.." Won a point!")
                    canPressFalse:FireServer()
                    restartRound:FireServer()
                    player.thePointsOne.Value = player.thePointsOne.Value + 1
                    break
                end
            end
            else
                print("Wait")
                break
            end
        end -- loop
        end)
    end
    end
end

1 answer

On line 22 and 23 + 29, that is the problem. This is yours:

                     if player.thePointsOne.Value == 5 then
                     print("You won the game")
                     player.thePointsOne.Value = player.thePointsOne.Value + 1

And on-line 29 was +1 = 5+1 = 6, that's why the key gave you 6 points. This is the correct ways:

For lines 22 and 23:

                     if player.thePointsOne.Value == 3 then
                     print("You got three points")

For lines 29:

If you want to give three points only:

                    player.thePointsOne.Value = player.thePointsOne.Value + 0

If you want to give 4 points only:

                    player.thePointsOne.Value = player.thePointsOne.Value + 1

You added +1 in line 29 so it made the points go up 1 extra and on line 22 and 23 you wrote 5 so that means 5 + 1 = 6 and you said it gives 6, there's your answer.

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