Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Currency donation script doesn't work with filtering enabled?

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)

1 answer

✓ Accepted answer

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!

1 comment

0

There's no 10k robux but i'm sure this helped i'll accept your answer

This discussion is preserved as it was. New answers, comments, and votes are closed.