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

Will firing events too fast cause lag?

Asked by 4 years ago
Edited 4 years ago

Hey guys, I'm new to Roblox studio and I'm trying to make a button that adds 1 Money when clicked.

I wrote something that works by firing a RemoteEvent. Is it conventional to do it like this? WIll it cause lag if I use an autoclicker?

Here are some snippets of my code:

LocalScript:

1--press button, fire remoteEvent
2button.MouseButton1Up:Connect(function()
3    local event = game.ReplicatedStorage:WaitForChild("test")
4    event:FireServer("Money", 1)
5    cashLabel.Text += 1
6end)

Script:

1--recieves remoteEvent, stores values
2local mod = require(game.ServerStorage.storageClass)
3local event = game.ReplicatedStorage:WaitForChild("test")
4 
5event.OnServerEvent:Connect(function(player, name, value)
6    --saves the money on the server
7    mod.setStat(player, name, value)
8end)

ModuelScript: ~this is DataStore script that I copied off the Roblox website, it's a snippet but dw the script works fine

01local sessionData = {}
02 
03function mod.setStat(player, name, value)
04    local uID = "Player_" .. player.UserId
05    assert(typeof(sessionData[uID][name]) == typeof(value), "setStat error: types do not match")
06    if typeof(sessionData[uID][name]) == "number" then
07        sessionData[uID][name] = sessionData[uID][name] + value
08    else
09        sessionData[uID][name] = value 
10    end
11end

Answer this question