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

How to make an event happen on only the Client that clicked the button/part?

Asked by 4 years ago
Edited 4 years ago

I've been trying to make a Click for Cash button in Roblox, only to find out that the cooldown/debounce can also happen to other players. I've tried switching the Scripts to Local Scripts, but it does not work (I'm a beginner at coding) This is my code right now (Getting Money Script):

local cooldown = false
local COOLDOWN_TIME = 10

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

local clickDetector = script.Parent.ClickDetector

local timeRemaining = 10

clickDetector.MouseClick:Connect(function(player)
    if cooldown == false then
        cooldown = true
        player.leaderstats.Money.Value = player.leaderstats.Money.Value + math.random(1,200) * math.random(1,500) - math.random(1,5000)
        repeat
            print(timeRemaining)
            wait(1)
            timeRemaining = timeRemaining - 1
        until timeRemaining == 0
        if timeRemaining == 0 then
            cooldown = false
            timeRemaining = 10
        else
            return
        end
    elseif cooldown == true then
        return
    end
end)

(Cooldown Appearance Script):

local cooldown = false
local CD = script.Parent.ClickDetector

CD.MouseClick:Connect(function()
    if cooldown == false then
        cooldown = true
        for count = 10, 0, -1 do
            script.Parent.Parent.ClickGiveMoneyBase.BillboardGui.TextLabel.Text = count
            wait(1)
        end
        script.Parent.Parent.ClickGiveMoneyBase.BillboardGui.TextLabel.Text = "Click this Button to Give you CASH!"
        cooldown = false
    elseif cooldown == true then
        return
    end
end)

More clearance to my problem: When a player clicks and cooldown happens, it not only happens on the player that clicked the part, but also on other players in the server.

1 answer

Log in to vote
-1
Answered by 4 years ago
Edited 4 years ago

Move the localscript to StarterPlayer > StarterCharacterScripts > here, then Press workspace and on properties enable FilteringEnabled, then change

local clickDetector = script.Parent.ClickDetector

to

local clickDetector = workspace.Button.ClickDetector --Whatever the path is

because the parent wont be the button more. Also when adding the money of the button make it via Remote functions and to prevent exploiters add also a cooldown on the Remote function

0
WHY DOWNVOTE AlvaroG23 9 — 4y
0
Hello there! I don't know how to change the scripts to work via remote function. Can you help with this? (I have McDonald's-level WiFi so I can't open ROBLOX Studio yet) krowten024nabrU 463 — 4y
0
Also I didn't downvote you. krowten024nabrU 463 — 4y
0
Nvm, fixed it. krowten024nabrU 463 — 4y
0
Nevermind the nvm, cooldown still appears on other ppl. krowten024nabrU 463 — 4y
Ad

Answer this question