Am a beginner dev don’t judge, anyway I tried to make a system where if a UI button is clicked it will fire a RemoteFunction which should add to the player’s Cash value in leaderstats but the button just doesnt do anything. Will try Knit if all else fails
--Server code
local function GiveCash(player, amount)
print("player "..player.Name.." is getting cash via remotefunc")
local ls = player.leaderstats
local cash = ls.Cash
local yes, no = pcall(function()
if amount then
cash.Value = cash.Value + amount
end
end)
if no then
warn("giving cash failed, player "..player.Name.." ,reason "..no)
end
if yes then
print("gave cash to "..player.Name.." ("..player.UserId..") via button remoteevent")
end
end
game.ReplicatedStorage.GiveCash.OnServerInvoke = GiveCash```
--Client code
script.Parent.CashButton.Activated:Connect(function()
game.ReplicatedStorage.GiveCash:InvokeServer(game.Players.LocalPlayer, 20)
end)
Nope, button is still dead. Code is similar tho. Tried Knit, didnt work too.
--server
game.ReplicatedStorage.GiveCash.OnServerEvent:Connect(function(player, amount)
print("player "..player.Name.." is getting cash via remotefunc")
local ls = player.leaderstats
local cash = ls.Cash
local yes, no = pcall(function()
if amount then
cash.Value = cash.Value + amount
end
end)
if no then
warn("giving cash failed, player "..player.Name.." ,reason "..no)
end
if yes then
print("gave cash to "..player.Name.." ("..player.UserId..") via button remoteevent")
end
end)
which will give them infinite, also you should use a remotevent for this.
Also apply some sanity cheks to this, this will still allow them to get infinite cash but will supply some checks to erroring the code, the client should not be in charge of how much cash it gets:
Code
--> Server Script, make GiveCash a RemoteEvent.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Cache = {} --> Ratelimit them
ReplicatedStorage.GiveCash:OnServerEvent:Connect(function(Player, Amount)
if type(Amount) ~= "number" then
return -- Detects Passing a Non Number
end
if Amount ~= Amount then
return -- Detects Passing NaN
end
if Cache[Player] and os.clock() - Cache[Player] < 0.5 the
return --> If it gets fired one at a time in less then 0.5 seconds it will ignore it, this stops spamming it
end
Cache[Player] = os.clock()
Player.leaderstats.Cash.Value += Amount
end)
--> Client Code
local ReplicatedStorage = game:GetService("ReplicatedStorage")
ReplicatedStorage.GiveCash:FireServer(20)