I think I’m not explaining it correctly sorry, so the user can click the button and gain one coin; or they can hold the button and gain 2 coins per second (one coin everfy half second). But that coins per second could be upgraded to 20. this is what im having issues with si like how do i impliment that without remote events since the user could hold for a half a seocnd for exmaple, or i could do simething with every second i update on server until release
No. I understood what you said perfectly. The method you are trying to wrap is just inefficient and causes issues.
Client and Server communication is NOT POSSIBLE without RemoteEvents / RemoteFunctions (which is almost the same as RemoteEvents)
My response implies that you are supposed to store the player’s calculated gains (Default coin game * multipliers) on the server and have the player fire the RemoteEvent per click (just so you don’t have to repeat firing the RemoteEvent every click for the upgrades). This way, when they hold, the client fires RemoteEvent only twice per second and not 29737292 depending on the upgrades.
As @nvthane said, it wouldn’t be possible to communicate between server/client without using RemoveEvents/Functions. With this in mind, the most secure & efficient way to do this is to have 2 RemoteEvents, one for the MouseButtonDown and the other for the MouseButtonUp. When a player presses down the textbutton, fire the MouseButtonDown RemoveEvent and when the textbutton is released, fire the MouseButtonUp RemoveEvent. On the server, when each RemoteEvent has been fired, store a time in which they were done so.
Example
-- LocalScript (in StarterPlayerScripts)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local PlayerGui = Players.LocalPlayer.PlayerGui
local TextButton = -- the location of your textbutton
local MouseDownEvent = ReplicatedStorage.MouseDownEvent
local MouseReleaseEvent = ReplicatedStorage.MouseReleaseEvent
TextButton.MouseButton1Down:Connect(function()
MouseDownEvent:FireServer()
end)
TextButton.MouseButton1Up:Connect(function()
MouseReleaseEvent:FireServer()
end)
-- ServerScript (in ServerScriptService)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local MouseDownEvent = ReplicatedStorage.MouseDownEvent
local MouseReleaseEvent = ReplicatedStorage.MouseReleaseEvent
local down = {} -- use a table to store each player's time
local release = {}
MouseDownEvent.OnServerEvent:Connect(function(player)
-- tick(), time in which the textbutton was pressed
down[player] = tick() -- assigns each player a time, player acts as a key for the table
end)
MouseReleaseEvent.OnServerEvent:Connect(function(player)
release = tick()
delta = release - down
-- the average click is about 85ms or 0.085 seconds so 1 click can be detected as:
if delta < 0.085 then -- adjust to your preference
print("1 click has been made")
end
print("Button held for:", delta, "seconds!")
end)
Using the delta, you can do your math to calculate how many coins the player receives depending on their upgrades.
You could just use a server script to handle the making your coins go up whenever you click the button. While it’s not as optimal as just using a remote event it is more secure and you can still script most UI in a server script.
game.Players.PlayerAdded:Connect(function(player)
local button = player:WaitForChild('PlayerGui'):WaitForChild('ScreenGui'):WaitForChild('TextButton')
button.MouseButton1Click:Connect(function()
print('hi')
end)
end)
You can do that by tracking the number of clicks per second on the client-side and send this information to the server along with the coin gain request and then on the server-side, ensure the requests don’t exceed the maximum allowed rate (20x per second). Also, handle any multipliers from game passes.
Local Script Example (Client-side):
local button = script.Parent
local player = game.Players.LocalPlayer
local coinsEarned = 0
local clickCount = 0
local maxClicksPerSecond = 20 -- The maximum allowed clicks per second
local coinIncrement = 1 -- Adjust based on upgrades
local interval = 0.1 -- 10 times per second
-- Assuming the player has a gamepass, modify coin increment if applicable
local hasGamepass = -- logic to check if player has the gamepass
if hasGamepass then
coinIncrement = coinIncrement * 2
end
local function earnCoins()
if clickCount >= maxClicksPerSecond then return end
clickCount = clickCount + 1
coinsEarned = coinsEarned + coinIncrement
end
button.MouseButton1Down:Connect(function()
while button:IsPressed() do
earnCoins()
end
end)
-- Reset the click count every second
game:GetService("RunService").Stepped:Connect(function(time, deltaTime)
if deltaTime >= 1 then
clickCount = 0
end
end)
-- Periodically send accumulated coins to server
game:GetService("RunService").RenderStepped:Connect(function()
if coinsEarned > 0 then
game.ReplicatedStorage.CoinEvent:FireServer(coinsEarned, clickCount)
coinsEarned = 0
end
end)
Server Script Example:
local CoinEvent = Instance.new("RemoteEvent")
CoinEvent.Name = "CoinEvent"
CoinEvent.Parent = game.ReplicatedStorage
local maxClicksPerSecond = 20
CoinEvent.OnServerEvent:Connect(function(player, coins, clickCount)
-- Validate clicks per second
if clickCount > maxClicksPerSecond then
-- Optionally handle violation (e.g., warn the player, log the incident)
return
end
-- Validate and add coins to player
if typeof(coins) == "number" and coins > 0 then
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats then
local coinsStat = leaderstats:FindFirstChild("Coins")
if coinsStat then
coinsStat.Value = coinsStat.Value + coins
end
end
end
end)
Explanation:
Local Script:
Tracks the number of clicks per second (clickCount) and ensures it doesn’t exceed the limit (maxClicksPerSecond).
Adjusts the coin increment based on whether the player has a gamepass.
Resets the clickCount every second.
Sends the accumulated coins and clickCount to the server periodically.
Server Script:
Receives the coins and clickCount.
Validates that the clickCount does not exceed maxClicksPerSecond.
Adds the coins to the player’s total if validation passes.
you don’t need to do any of this? he wants it without a remote so he could just use a server script to make the UI work and he could detect how many times the button is clicked in a certain time frame. also this is some of the worst code ive ever seen never cook again its so exploitable.
how is this smart he gave u the complete opposite answer to your question when theres an answer which fits your question perfectly??? + its not even “clever” its just tick its common sense when you want to check how often a remote is being fired… + he didn’t even notice the dumb error in his script he’s doing tick() - table instead of tick() - table[player.Name]
I highly suggest you gain coins on click with Remote Events. If you do it without Remote Events, your game is easily exploitable and exploiters will be able to edit your LocalScript and give themselves a ridiculous number of coins.
why would he do it in a local script when a server script works fine for his question? am I just a higher being of intelligence or something why does it feel like everything in this thread is a monkey compared to me???
way more secure since they wouldn’t be able to spam the event to auto click??? also the script you gave him is STUPID. you do realise an exploiter can just fire the event with 0 clicks per second over and over again and never have the sanity checks on the server fire. WHY IS YOUR POST THE SOLUTION ITS NOT SOLVING ANYTHING IT JUST CAUSES MORE PROBLEMS AND IT DIDNT EVEN ANSWER HIS QUESTION PROPERLY??? AM I LIKE ALBERT EINSTEIN OR SOMETHING OR HAS EVERYONE JUST GOTTEN DUMBER OVER THE YEARS??? ITS COMMON SENSE??? IS IT THAT HARD TO THINK RATIONALLY???
The click count doesn’t secure this remote event. An exploiter could fire it with coins at 1 quadrillion and one click and it would still go through without issue. This would almost certainly lead to issues.
If he doesn’t know remote events then why don’t you just suggest him an actual solution that answers his question properly which is just using a server script to script the UI if he doesn’t want to use remote events then he properly knows how to use remote events and just doesn’t want to use them for some reason.
This code creates a leaderstats in your game with coins.
Now, add another Script in ServerScriptService, and name it coinsScript
Then paste that code in it.
game.Players.PlayerAdded:Connect(function(player)
local coinsButton = player.PlayerGui:WaitForChild("ScreenGui").CoinsButton
local coins = player.leaderstats.Coins
while coinsButton:IsPressed() do
task.wait(0.05)
coins.Value += 1
end
end)
I didn’t write in the script editor, so it may give you an error. If it did, tell me.