I have a shop script, but when an item is purchased it only removes the players cash locally and not server sided, may i have some help with this issue? Thanks.
Remote Function
local gungiveEvent = game.ReplicatedStorage.GunGiveEvent
gungiveEvent.OnServerEvent:connect(function(player, gun)
if game.ServerStorage:FindFirstChild(gun) then
local gun = game.ServerStorage:FindFirstChild(gun):Clone()
wait(1)
gun.Parent = player.Backpack
wait(999)
end
end)
Script in the text button
local event = game.ReplicatedStorage.GunGiveEvent
script.Parent.MouseButton1Click:connect(function()
if game.Players.LocalPlayer.leaderstats.Cash.Value >= 100 then
for i,v in pairs(game.Players:GetPlayers()) do
if v:FindFirstChild("leaderstats") then
v.leaderstats.Cash.Value = v.leaderstats.Cash.value - 100
event:FireServer("Kar98k")
end
end
end
end)

8 comments
I'm assuming the Script in the Text Button is Local yes?
If not, that's an issue, also, it would be adding directly to the Client anyway as it was told to, you have to use the ServerScript (ServerScriptService) to add the cash, from the Server.
ServerScripts and LocalScripts run in different environments; LocalScripts will only run directly for the Client, ServerScripts will only run directly for the Server. You need to use a ServerScript to have the desired work completed on the Server
so how would that be accomplished, because to my knowledge the RemoteEvent i have can only be triggered from a local script?
The code I have in my answer shows how to accomplish this. To make it easier to read you may have to hover over it and click "view source."
Since these Scripts' vulnerable, automatic communication, was disrupted, you have to manually communicate further on. RemoteEvents are used to Fire to the counterpart of the Script it's being used in, so you'd generically have to Fire from the LocalScript, yes.
Thanks to both of you guys, i appreciate your help! :)
No problem, and welcome to Scripting Helpers! If my answer helped please accept it so both of us can gain reputation :)