Exploit-proofing ore pickup system

I currently have a system where ores get dropped when mining a stone, and i want to increase the players ore amount every time you pick one up, i was planning on doing this via a RemoteEvent. The problem is that the only way i could think of how to do this would be to fire an event to the server every time an ore is picked up, but exploiters could just spam that event to gain an infinite amount of ores. I’m unsure how i would fix this issue, and would appreciate some advice on what to do.

Heres the script that sends the remote:

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local root = char:WaitForChild("HumanoidRootPart")

local ts = game:GetService("TweenService")
local rs = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local SoundService = game:GetService("SoundService")

RunService.Heartbeat:Connect(function()
	for i, drop in pairs(workspace.Drops:GetChildren()) do
		if drop:IsA("Part") then
			local magnitude = (root.Position - drop.Position).Magnitude
			if magnitude <= 8 then
				drop.CFrame = drop.CFrame:Lerp(root.CFrame,0.2)
				
				local touching = game.Workspace:GetPartsInPart(drop)
				local playerInPart = false
				for i, v in pairs(touching) do
					if v.Parent.Name == plr.Name then
						playerInPart = true
					end
				end
				
				if playerInPart then
					SoundService:PlayLocalSound(workspace.Sounds.PickupSound)
					--rs.Events.OrePickedUpEvent:FireServer()
					drop:Destroy()
				end
			end
		end
	end
end)

1 Like

You would pass the ore drop value to the server, and in the server you would check if the ore exists and if it’s touched by the player.

2 Likes

The problem is that the dropped ores are spawned in via a LocalScript, i dont want other players seeing them. I cant check if it exists from the server if it doesn’t exist on the server.

Can you spawn the ores on the server, mark the ore with what player got it and then make it invisible and non-collectable for other players by utilising that mark?

1 Like

Could i spawn them in through the server, but lerp and destroy them individually through every client (visual effect), and then check if the ore exists through the server, and if it does, destroy it and increase the ore value for the player? I’m aware that would make it so the ores spawn for everyone, but that’s fine. But do you think it’d work?

Yeah pretty much. You can make the ores not visible for players who didn’t collect it though.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.