I have a currency in my game and I wanted players to donate it to each other, the script does work without filtering enabled, so then I tried remoteevents but I can't figure how to transfer the amount values and everything since the server doesnt see inside the playergui.
here is the code of a LocalScript inside StarterGui, which fires a remoteevent.
player = game.Players.LocalPlayer currency = "Drachma" recipient = "" amount = 0 Frame = player.PlayerGui.DonationGUI.Frame Frame.Submit.MouseButton1Down:Connect(function() recipient = Frame.Player.Text amount = tonumber(Frame.Amount.Text) print("donate fired") game.ReplicatedStorage.Donate:FireServer(player,currency,recipient,amount) end)
here is the code of a server script inside ServerScriptService that recieves the RemoteEvent in ReplicatedStorage.
game.ReplicatedStorage.Donate.OnServerEvent:connect(function(player,currency,recipient,amount) if player.leaderstatss[currency].Value >= amount then -- Player has enough money to donate game.Players[recipient].leaderstatss[currency].Value = game.Players[recipient].leaderstatss[currency].Value + amount player.leaderstatss[currency].Value = player.leaderstatss[currency].Value - amount else print("not enough money") end end)
You don't need to send a player argument when firing the Server, that happens automatically and is always the first parameter.
Incorrect usage:
-- Local script workspace.RemoteEvent:FireServer(game.Players.LocalPlayer,1337)
-- Server script workspace.RemoteEvent.OnServerEvent:Connect(function(plr,number) print(plr) -- game.Players.Color3_fromRGB print(number) -- game.Players.Color3_fromRGB end)
Correct usage:
-- Local script workspace.RemoteEvent:FireServer(1337)
-- Server script workspace.RemoteEvent.OnServerEvent:Connect(function(plr,number) print(plr) -- game.Players.Color3_fromRGB print(number) -- 1337 end)
Hope I helped!