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:
--press button, fire remoteEvent button.MouseButton1Up:Connect(function() local event = game.ReplicatedStorage:WaitForChild("test") event:FireServer("Money", 1) cashLabel.Text += 1 end)
Script:
--recieves remoteEvent, stores values local mod = require(game.ServerStorage.storageClass) local event = game.ReplicatedStorage:WaitForChild("test") event.OnServerEvent:Connect(function(player, name, value) --saves the money on the server mod.setStat(player, name, value) end)
ModuelScript: ~this is DataStore script that I copied off the Roblox website, it's a snippet but dw the script works fine
local sessionData = {} function mod.setStat(player, name, value) local uID = "Player_" .. player.UserId assert(typeof(sessionData[uID][name]) == typeof(value), "setStat error: types do not match") if typeof(sessionData[uID][name]) == "number" then sessionData[uID][name] = sessionData[uID][name] + value else sessionData[uID][name] = value end end