How do i make anti-steal ore system

  1. What do you want to achieve? Keep it simple and clear!
    So currently i’m working on anti-steal system of ores, if one player already hit it, other can’t do it
  2. What is the issue? Include screenshots / videos if possible!
    Idk how to do that
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub? I tryed to use value for it. but when i change value to other person, i still can mine it

Here is code:

local Rock = script.Parent
local SettingsUI = Rock.Settings
local OreDrop = game:GetService("ReplicatedStorage").OreThings.Coal
local swingsLeft = 15
local TweenService = game:GetService("TweenService")
local RegenerateTimer = 10
local OreDropped = false
local OwnerVal = script.Parent.OwnerVal
local function Regenerate()
	local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0, false, 0)
	local Goal = {Size = Vector3.new(4,2,4)}
	local tweenInfo2 = TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0, false, 0)
	local Goal2 = {Size = Vector3.new(4,2,4)}
	local Tween = TweenService:Create(Rock, tweenInfo, Goal)
	local Tween2 = TweenService:Create(Rock.Parent.Union, tweenInfo2, Goal2)
	Tween:Play()
	Tween2:Play()
	while RegenerateTimer > 0 do
		SettingsUI.Frame.OreName.TextLabel.Text = "REGENERATING: "..RegenerateTimer.."s"
		RegenerateTimer -= 1
		wait(1)
	end
	if RegenerateTimer == 0 then
		local tweenInfo1 = TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0, false, 0)
		local Goal1 = {Size = Vector3.new(6.3, 3.15, 6.3)}
		local tweenInfo3 = TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0, false, 0)
		local Goal3 = {Size = Vector3.new(3.5, 6.5, 6.4)}
		local Tween1 = TweenService:Create(Rock, tweenInfo1, Goal1)
		local Tween3 = TweenService:Create(Rock.Parent.Union, tweenInfo3, Goal3)
		Tween1:Play()
		Tween3:Play()
		swingsLeft = 15
		OreDropped = false
		SettingsUI.Frame.HealthFrame.Frame.Frame:TweenSize(UDim2.new(0.98,0,1,0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quad, 1, true)	
		SettingsUI.Frame.OreName.TextLabel.Text = "Coal Ore ("..swingsLeft.."/15)"
		RegenerateTimer = 10
	end
end
local function onTouch(otherPart)
	local tool = otherPart.Parent
	if tool:IsA('Tool') and tool.Mining.Value == true then
		if swingsLeft > 0 then
			if OwnerVal.Value == tool.Parent.Name or "" then --Anti Steal System
				OwnerVal.Value = tool.Parent.Name --Anti Steal System
				print("Player is owner") --Anti Steal System
		if tool.Name == "OwnerPickaxe" then
			swingsLeft -=15
			tool.Mining.Value = false
			SettingsUI.Frame.OreName.TextLabel.Text = "Coal Ore ("..swingsLeft.."/15)"
			SettingsUI.Frame.HealthFrame.Frame.Frame:TweenSize(UDim2.new(swingsLeft/15,0,1,0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quad, 1, true)
		else
			swingsLeft -= 1
			tool.Mining.Value = false
		SettingsUI.Frame.OreName.TextLabel.Text = "Coal Ore ("..swingsLeft.."/15)"
		SettingsUI.Frame.HealthFrame.Frame.Frame:TweenSize(UDim2.new(swingsLeft/15,0,1,0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quad, 1, true)	
			end
			end
		end
	if swingsLeft <= 0 then
		if OreDropped == false then
			OreDropped = true
			local OreDropClone = OreDrop:Clone()
			local NewY = Rock.Position.Y + 5
		OreDropClone.Position = Vector3.new(Rock.Position.X,NewY,Rock.Position.Z)
		OreDropClone.Parent = workspace
			Regenerate()
			end
			end
	end
end

Rock.Touched:Connect(onTouch)

creating some sort of… Table,

when some player hits something, the name will be inserted inside a ‘‘Mining’’ table, and if someone else try to hit, the name will not be inserted, since the Limit is 1 ( max players that can mine at the same time the ore)

Hmm, i’m using an value inside of rock for that i don’t really wanna use tables there tho, since i don’t understand them really good

You Could add a value into the Rock and doing the same thing as Moleza.
So, Like add a string value and when a player hits the string value will be the player name

Then just insert the username (since you wont expect players to change their username while still in-game right?), or user ID (altho I really dont think anyone gonna be changin their username IN game) and then just check using a script if the player doing the mining has the correct value

Oh wait i forgot to mention

OwnerVal == "" then

I used

== "" then

Yeah, better of using ID though because its safer.

Alright now i can’t use it when value is not my name

But how i get PlayerID? (30 letters)

So the final solution is Add a string value into the Rock
Once a Player hits the Rock their userid will be in the string value when a Player hits again check if the player userid is the Player that name is in the string value and if not then return

This line will check if the owner’s value == tool.Parent.Name. If this is true, the if statement passes. If this is false, the or "" will return "", which also evaluates to true.
Fixing this ought to be trivial if you keep this in mind.

Already made that, here is code tho:

local Rock = script.Parent
local SettingsUI = Rock.Settings
local OreDrop = game:GetService("ReplicatedStorage").OreThings.Coal
local swingsLeft = 15
local TweenService = game:GetService("TweenService")
local RegenerateTimer = 10
local OreDropped = false
local OwnerVal = script.Parent.OwnerVal
local function Regenerate()
	local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0, false, 0)
	local Goal = {Size = Vector3.new(4,2,4)}
	local tweenInfo2 = TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0, false, 0)
	local Goal2 = {Size = Vector3.new(4,2,4)}
	local Tween = TweenService:Create(Rock, tweenInfo, Goal)
	local Tween2 = TweenService:Create(Rock.Parent.Union, tweenInfo2, Goal2)
	Tween:Play()
	Tween2:Play()
	while RegenerateTimer > 0 do
		SettingsUI.Frame.OreName.TextLabel.Text = "REGENERATING: "..RegenerateTimer.."s"
		RegenerateTimer -= 1
		wait(1)
	end
	if RegenerateTimer == 0 then
		local tweenInfo1 = TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0, false, 0)
		local Goal1 = {Size = Vector3.new(6.3, 3.15, 6.3)}
		local tweenInfo3 = TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0, false, 0)
		local Goal3 = {Size = Vector3.new(3.5, 6.5, 6.4)}
		local Tween1 = TweenService:Create(Rock, tweenInfo1, Goal1)
		local Tween3 = TweenService:Create(Rock.Parent.Union, tweenInfo3, Goal3)
		Tween1:Play()
		Tween3:Play()
		swingsLeft = 15
		OreDropped = false
		SettingsUI.Frame.HealthFrame.Frame.Frame:TweenSize(UDim2.new(0.98,0,1,0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quad, 1, true)	
		SettingsUI.Frame.OreName.TextLabel.Text = "Coal Ore ("..swingsLeft.."/15)"
		RegenerateTimer = 10
	end
end

local function onOwnerLeft(Owner) -- now i'm making if owner left the game
	local pName = OwnerVal.Value
	if game:GetService("Players"):FindFirstChild(pName) then
		return
	else
		OwnerVal.Value = ""
	end
end

local function onTouch(otherPart)
	local tool = otherPart.Parent
	if tool:IsA('Tool') and tool.Mining.Value == true then
		if swingsLeft > 0 then
			if OwnerVal.Value == tool.Parent.Name or OwnerVal.Value == "" then --Anti Steal System
				OwnerVal.Value = tool.Parent.Name --Anti Steal System
				print("Player is owner") --Anti Steal System
		if tool.Name == "OwnerPickaxe" then
			swingsLeft -=15
			tool.Mining.Value = false
			SettingsUI.Frame.OreName.TextLabel.Text = "Coal Ore ("..swingsLeft.."/15)"
			SettingsUI.Frame.HealthFrame.Frame.Frame:TweenSize(UDim2.new(swingsLeft/15,0,1,0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quad, 1, true)
		else
			swingsLeft -= 1
			tool.Mining.Value = false
		SettingsUI.Frame.OreName.TextLabel.Text = "Coal Ore ("..swingsLeft.."/15)"
		SettingsUI.Frame.HealthFrame.Frame.Frame:TweenSize(UDim2.new(swingsLeft/15,0,1,0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quad, 1, true)	
			end
			end
		end
	if swingsLeft <= 0 then
		if OreDropped == false then
			OreDropped = true
			local OreDropClone = OreDrop:Clone()
			local NewY = Rock.Position.Y + 5
		OreDropClone.Position = Vector3.new(Rock.Position.X,NewY,Rock.Position.Z)
		OreDropClone.Parent = workspace
			Regenerate()
			end
			end
	end
end

Rock.Touched:Connect(onTouch)

Its a Property inside a Player
so like Player.UserId

Did it work???
if It did Mark it as a solution.
if not tell me which line?

Alright can’t use UserId although i’m just gonna use plr name, i don’t think anyone gonna change name in game and also i have code for that, if you can’t find owner in game then value become “”

insert some IntValue on the rock, then The first user to hit will be inserted, after a blink of time it will send to the server that someone is mining Rock A, the server will record that action, and until the ore is destroyed, or cancelled, the player will be on the variable (IntValue is the playerId that will be inserted)
and when someone else click on the rock A

(if legit normal player) : he can’t mine it, since locally there is a script that inserted the userId on the rock A

(If exploiter) : they can change the ID ( someone is already mining )

and he will try to insert in 0.04129419 seconds their ID

it will not work, and if somehow the hacker destroy the rock first, he will not receive the Ore,
because on the server side, the first user already recorded his name on Rock A

see how server is anti-exploitable

But they can insert their id on all rocks ! what

  • yea they can, and if they do that, the server will check if they have some pickaxe, distance from the Rock A, if something is wrong and not possible, the server will perma ban, because exploiters ruins alot of things

Oh, I think they can’t change doesn’t change in game anyways.