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

The script works only for one part but not for the another ones?

Asked by 4 years ago
Edited 4 years ago

I'm currently developing a simulator game and I want to make people spam on the blocks. I have a problem and it is that this script works for one block:

local firstPart = game.Workspace.firstPart
local secondPart = game.Workspace.secondPart
local thirdPart = game.Workspace.thirdPart

local oneClick = 10

game.Players.PlayerAdded:Connect(function(plr)
    local LS = Instance.new("Folder", plr)
    LS.Name = "leaderstats"

    local test = Instance.new("IntValue", LS)
    test.Name = "Test"

    firstPart.ClickDetector.MouseClick:Connect(function()
        test.Value = test.Value + oneClick
    end)

    if test.Value >= 100 then
        secondPart.ClickDetector.MouseClick:Connect(function()
            test.Value = test.Value + oneClick * 5
        end)
    end

    if test.Value >= 500 then
        thirdPart.ClickDetector.MouseClick:Connect(function()
            test.Value = test.Value + oneClick * 25
        end)
    end
end)

I don't know what to do, it doesn't say there's any error but it doesn't work for the second part and the third one. And yes, I have tried several things but they did not work either.

0
The problem is specifically is that the script works for one block and not the 2 others, there also are no errors in the console. DangerousKillerTimur 54 — 4y
0
Have you added 100+ value to Test before clicking on the second block, and the same but with 500 on the third block? Because I don't really see something wrong here. User#32819 0 — 4y
0
Yes even when the Test's value has 100+ points, the second block doesn't work. It goes to the third as well. DangerousKillerTimur 54 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

I think that it is because it only connects once the player joins AND test.Value is greater or equal than 100 or 500. When the requirement is met the event is not connected because the player already joined and the event PlayerAdded was already fired. Try to move the check for test.Value inside of the function that is being connected to the event.

0
Ok, I will try. DangerousKillerTimur 54 — 4y
Ad

Answer this question