Basically, I need help to make a check for if the player touches a coin but it needs to be on the server, or else it is very easily exploitable. I can identify the player and the part but I don't know how to actually check if the player actually touched the part on the server.
The coin touched script. (LocalScript located in the StarterCharacterScripts folder)
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local rs = game:GetService("ReplicatedStorage")
local remote = rs:WaitForChild("touchedEvent")
local debounce = false
local touched = humanoid.Touched:Connect(function(hit) -- hit = the coin
if debounce then
return
end
-- if part not in coin folder, return
if hit.Parent ~= workspace.CoinStorage then
return
end
remote:FireServer(hit) -- pass the coin to the server
debounce = true
wait(0.5)
debounce = false
end)
The server script (Script located in ServerScriptService)
local rs = game:GetService("ReplicatedStorage")
local remote = rs:WaitForChild("touchedEvent")
remote.OnServerEvent:Connect(function(player, part) -- player is who touched the coin, and part is the coin itself
local leaderstats = player:WaitForChild("leaderstats")
local coins = leaderstats:WaitForChild("Coins")
local amount = part:WaitForChild("Amount") -- numbervalue in the coin
coins.Value = coins.Value + amount.Value
part:Destroy()
end)

1 comment
If you have any problems tell me