Hello. So I’m trying to make a menu that only I can use to give people coins. How it works is I type the amount into the “Amount” box and the player who I want to give the coins to into the “Player” box and click “Confirm” and it gives them the coins.
Here is a picture of the menu:
Here is my code (Script is inside the “Confirm” button.
script.Parent.MouseButton1Click:Connect(function()
local Amount = tonumber(script.Parent.Parent.Amount.Text)
local Player = tostring(script.Parent.Parent.Player.Text)
if Amount ~= nil and Player ~= Player then
game.Players:FindFirstChild(Player).leaderstats.Coins.Value += Amount
end
end)
Note this is a Server Script.
Thanks!
2 Likes
You need to use a local script since it is in a gui object.
And also, can you tell me why you are checking if Player is not equal to Player because this is also breaking your script.
2 Likes
The reason I made it a server script is so that exploiters can’t use the remote event to manipulate the menu and give themselves coins
EDIT: Though now that I’m thinking about it I could just detect to see if the player is not me and if they are not then it destroys the Remote event on their client
1 Like
You must use local scripts on the client (gui elements, starter player scripts) but you can prevent exploiters by making remote events and doing background checks on a script in ServerScriptService.
2 Likes
Would that be like I said in my edit above?
That’s not really how it works; exploiters can change anything on the client, so the only way to prevent exploiters is by making a remote event that connects to a script on the server.
On the server, you can do background checks to make sure the player has enough money and exploiters cannot bypass these checks.
On your local script in the Confirm button, do
script.Parent.MouseButton1Click:Connect(function()
game.ReplicatedStorage.RemoteEvent:FireServer()
-- ^^ replace RemoteEvent with the name of your remote event.
end)
And on the server, do
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player)
-- ^^ replace RemoteEvent with the name of your remote event.
-- if player has enough money then change leaderstats
end)
2 Likes
Ah I see so what I would do is on the server script I would check to see if their UserId is the same as mine and if it is then it gives the coins?
Just tried that and it worked perfectly! Thank you so much!
1 Like