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

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

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

✓ Accepted answer

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

5 comments

0

WHY DOWNVOTE

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)

0

Also I didn't downvote you.

0

Nvm, fixed it.

0

Nevermind the nvm, cooldown still appears on other ppl.

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