Hello everyone, in my game, I made a coin system, that when the player touches the coin, a certain amount gets added to his account. However, I just realized that I am calling a remoteEvent
from the client to the server, and that exploiters could just spam this remoteEvent
. I thought that the solution to this would be to check if the coin is touched on the server and add the coins, and then fire to client to add the UI. I just wanted to see if there was another solution, or if the remoteEvent is already secured. Here is the localscript.
local Players = game:GetService("Players")
local Sounds = workspace:WaitForChild("Sounds")
local coinSound = Sounds:WaitForChild("CoinSound")
local part = workspace:WaitForChild(script.Name)
local player = Players.LocalPlayer
local gui = script.Parent.Parent
local textLabelPoints = gui:WaitForChild("Points")
local textLabel = textLabelPoints:Clone()
textLabel.Parent = gui
textLabel.Name = "PointsClone"
local destroyed = false
local remoteEvent = game.ReplicatedStorage:WaitForChild("AddPointsNight")
local MoonCoinValue = game.ReplicatedStorage:WaitForChild("MoonCoinValue").Value
local Num = math.random(1, 4)
part.Touched:Connect(function(Hit)
local humanoid = Hit.Parent:FindFirstChild("Humanoid")
if humanoid then
local char = humanoid.Parent
local player = game.Players:GetPlayerFromCharacter(char)
if not destroyed and player == game.Players.LocalPlayer then
if Num == 1 then
textLabel.Position = UDim2.new(0.639, 0, 0.761, 0)
elseif Num == 2 then
textLabel.Position = UDim2.new(0.14, 0, 0.583, 0)
elseif Num == 3 then
textLabel.Position = UDim2.new(0.205, 0, 0.219, 0)
elseif Num == 4 then
textLabel.Position = UDim2.new(0.599, 0, 0.191, 0)
end
textLabel.Text = "+"..MoonCoinValue
textLabel.Visible = true
destroyed = true
coinSound:Play()
remoteEvent:FireServer()
part:Destroy()
wait(1.2)
textLabel:Destroy()
end
end
end)
This is the server side script.
local remoteEvent = game.ReplicatedStorage:WaitForChild("AddPointsNight")
remoteEvent.OnServerEvent:Connect(function(player)
local accumulatedCoins = player:WaitForChild("accumulatedCoins")
accumulatedCoins.Value = accumulatedCoins.Value + 3
end)
Thank you