So I have this database editor GUI that is supposed to change the amount of cash you have. But it does not work correctly.
Local Script:
script.Parent.MouseEnter:Connect(function() if script.Parent.Text ~= "" then script.Parent.BackgroundTransparency = 0 end end) script.Parent.MouseLeave:Connect(function() script.Parent.BackgroundTransparency = 1 end) local debounce = false script.Parent.MouseButton1Click:Connect(function() if not debounce then debounce = true wait() if script.Parent.Text ~= "" then local rs = game:GetService("ReplicatedStorage") local ev = rs:WaitForChild("ENCRYPTED") repeat wait() until ev local whoFired = game.Players.LocalPlayer local amount = script.Parent.Text local otherPlayer = script.Parent.Parent.Parent.PlayerName.Text ev:FireServer(whoFired,amount,otherPlayer) wait(5) debounce = false end end end)
Server Script:
function en1(whoFired,amount,otherPlayer) print(""..whoFired.." just gave".." "..otherPlayer.." +"..amount"$") if otherPlayer ~= nil then otherPlayer.leaderstats["Cash"].Value = amount end end script.Parent.OnServerEvent:Connect(en1)
In your local script, you're passing the LocalPlayer as a parameter in :FireServer() when you don't need to.
Your server Script event looks like this when you do that:
function onRequest(client, client, argument2) --A OnServerEvent always gives you the client since its the client that fired --argument2 is your "amount" in actuality end RemoteEvent.OnServerEvent:Connect(onRequest)
You should also keep any defined services and helpful variables outside of local scopes. This could help with performance in the long term.
I believe the local script is the only one needed to be edited:
local RS = game:GetService("ReplicatedStorage") local event = RS:WaitForChild("ENCRYPTED") script.Parent.MouseEnter:Connect(function() if script.Parent.Text ~= "" then script.Parent.BackgroundTransparency = 0 end end) script.Parent.MouseLeave:Connect(function() script.Parent.BackgroundTransparency = 1 end) local debounce = false script.Parent.MouseButton1Click:Connect(function() if not debounce then debounce = true if script.Parent.Text ~= "" then local amount = script.Parent.Text local otherPlayer = script.Parent.Parent.Parent.PlayerName.Text event:FireServer(amount, otherPlayer) wait(5) debounce = false end end end)
No need to get the LocalPlayer or pass them inside of the :FireServer() since the RemoteEvent takes care of it. Read up on RemoteEvents Client-to-Server for an in-depth explanation.