How do I use a RemoteEvent to send points to the user?

Hello! I am wondering how to use a remote event to give the user Points. (Points is a leaderstat.) Heads up: I have no experience with using remote events

  1. What do you want to achieve?
    I want to make it so when I click a TextButton a player will get more points.

  2. What is the issue?
    I have no idea how to use remote events, therefore I don’t know how to do this.

  3. What solutions have you tried so far?
    I watched a few youtube tutorials and read some posts.

When I click a button, a player that I specified should get (Points Amount) of points.

I don’t expect to get a whole tutorial on how to use these… just a short explaination would be great.

Ok so, when the player clicks that button you have to run the MouseButton1Click function and when you run that you have to basically just fire the server with the player. So you first define the player. Ex. local player = game.Players.LocalPlayer

Then you would say something like game.ReplicatedStorage.(RemoteEvent Name):FireServer(player)

Once that is done the server can get the leaderstats. So then you would just say player.leaderstats.Points.Value = player.leaderstats.Points.Value + (Points Amount)

3 Likes

I would recommend reading this as it explains it pretty well.

2 Likes

A RemoteEvent is designed to provide a one-way message between the server and clients, allowing Scripts to call code in LocalScripts and vice-versa. This message can be directed from one client to the server, from the server to a particular client, or from the server to all clients.


First, Insert a remote event inside ReplicatedStorage and name it “GivePoints”.

Then insert a script inside ServerScriptService and name it GivePointsEvent

Inside the Script put:

local Event = game.ReplicatedStorage:WaitForChild("GivePoints")

Event.OnServerEvent:Connect(function(player)
	player.leaderstats.Points.Value = player.leaderstats.Value + 50
	
end)

Now that we set up the server let’s set up the client!

Inside the TextButton Insert a LocalScript and name it GivePointsScript.

In the LocalScript put:

local Event = game.ReplicatedStorage:WaitForChild("GivePoints")
local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	Event:FireServer(player)
end)

And that’s it!

Hope this helped you.

6 Likes

You don’t have to fire the player through the remote, by default the player is the first argument of .OnServerEvent :slight_smile:

1 Like

Thank you so much for this! It works perfectly!

I recommend adding a debounce to prevent exploiters from spamming the remote giving themselves tons of points.

@vsefu1 Also, you can do += 50 to keep it short.

player.leaderstats.Points.Value += 50
1 Like

Thanks for the info i never knew about that!

No problem, it’s called compound assignments and came in Luau.

1 Like

You could just add a server check, and then the exploiters won’t get any points from firing it. Way better than giving them the chance to get a few points, right?

2 Likes

That was just my recommendation; if he has another method of preventing exploiters, he can do that.

1 Like

Well, I think it’s important to learn the never-trust-the-client rule since you start messing with remote requests, I sadly started scripting with alvinblox’es tutorials, and he does the checks on the client he doesn’t do these mistakes anymore, but my game still got exploited because of me not checking things on the server.

2 Likes