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

Why wont the clicks come through?

Asked by 1 year ago

I tried to alter a script where when u click you get 1 click, but with 50 coins you can buy 1.5x clicks. Here is my script:

local button = script.Parent
local player = button:FindFirstAncestorOfClass("Player")
repeat
    player = button:FindFirstAncestorOfClass("Player")
    task.wait()
until player ~= nil

local debounce = true
button.MouseButton1Click:Connect(function()
    if debounce then -- if debounce is true
        debounce = false

        local leaderstats = player:WaitForChild("leaderstats")
        local Clicks = leaderstats:WaitForChild("Clicks")
        Clicks.Value += 1

        if game.StarterGui.Shop.ShopFrame.X1dot5.MouseButton1Click then -- here is what I add and it does not work
            if game.Players.LocalPlayer.leaderstats.Coins.Value == 50 then
                Clicks.Value +=0.5
            end
        end








        task.delay(0.5, function() -- after 1 second, debounce will turn true
            debounce = true
        end)
    end
end)

Thanks for helping!

0
Try using prints to narrow down the issue like this print("Test") theking66hayday 841 — 1y

2 answers

Log in to vote
2
Answered by 1 year ago
Edited 1 year ago

The script you're using is my script. What you did in line 17 is wrong. It won't work when you click the button only. It works because it checks if MouseButton1Click exists, which it does. What you will do is copy line 9.

Player.PlayerGui.Shop.ShopFrame.X1dot5.MouseButton1Click:Connect(function()

Also you can just put it outside button.MouseButton1Click.

Final script:

local button = script.Parent
local player = button:FindFirstAncestorOfClass("Player")
repeat
    player = button:FindFirstAncestorOfClass("Player")
    task.wait()
until player ~= nil

local debounce = true
button.MouseButton1Click:Connect(function()
    if debounce then
        debounce = false

        local leaderstats = player:WaitForChild("leaderstats")
        local Clicks = leaderstats:WaitForChild("Clicks")
        Clicks.Value += 1

        task.delay(0.5, function()
            debounce = true
        end)
    end
end)

local debounce2 = true
player.PlayerGui.Shop.ShopFrame.X1dot5.MouseButton1Click:Connect(function()
    local leaderstats = player:WaitForChild("leaderstats")
    local Clicks = leaderstats:WaitForChild("Clicks")
    local Coins = leaderstats:WaitForChild("Coins")

    if (Coins.Value >= 50) and debounce2 then
        debounce2 = false
        Clicks.Value += 1.5

        task.delay(0.5, function()
            debounce2 = true
        end)
    end
end)
0
The repeat loop is pointless... The player will need to be loaded anyway in order for the script to load, as it is a descendant of the player. xInfinityBear 1777 — 1y
Ad
Log in to vote
0
Answered by 1 year ago

first on line 2 you can do:

local player = game:GetService("Players").LocalPlayer

It works better and is more reliable. the repeat loop from line 3 to 6 can go, player is already defined and looping something over it is worthless.

to solve the actual issue you asked about try this:

on line 19 instead of:

Clicks.Value +=0.5

do:

Clicks.Value *=1.5

changing the + symbol to a * makes it multiply instead. we change 0.5 to 1.5 because otherwise you lose clicks.

0
P.S. you may want to clarify what EXACTLY the problem is, I am guessing that this solves it but I may be thinking about it wrong, so for future reference make sure to clarify what the problem is more Verse_NOVA 52 — 1y

Answer this question