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
What do you want to achieve? I want to make it so when I click a TextButton a player will get more points.
What is the issue? I have no idea how to use remote events, therefore I don’t know how to do this.
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)
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
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)
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?
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.