Im making a mining system that will give you money after you break an ore but the ore doesnt break. Here’s a video
Script:
local plr = game.Players.LocalPlayer
local char = plr.Character
local mouse = plr:GetMouse()
local tool = script.Parent
local Mine = tool:WaitForChild("Mine")
local MTrack = char.Humanoid.Animator:LoadAnimation(Mine)
local mining = false
local TS = game:GetService("TweenService")
local function RespawnTargetOre(target)
if plr:FindFirstChild("mined") then
plr.mined.Value += target.MaxHP.Value
end
local TClone = target:Clone()
TClone.HealthBar:Destroy()
TClone.HP.Value = TClone.MaxHP.Value
game.ReplicatedStorage.REs.Mined:FireServer(target.MaxHP.Value, target.Name)
wait(30)
TClone.Parent = workspace.Map.Ores
end
tool.Activated:Connect(function()
local target = mouse.Target.Parent
if not mining and (char.HumanoidRootPart.Position - mouse.Target.Position).Magnitude <= 30 then
mining = true
MTrack:Play()
if target:FindFirstChild("HP") and target:FindFirstChild("MaxHP") then
if target:FindFirstChild("HP").Value == 1 then
task.spawn(RespawnTargetOre, target)
else
target:FindFirstChild("HP").Value -= 1
if not target:FindFirstChild("HealthBar") then
local HBar = game.ReplicatedStorage.HealthBar:Clone()
HBar.Parent = target
end
TS:Create(target.HealthBar.Frame.Frame, TweenInfo.new(0.25, Enum.EasingStyle.Quad), {Size = UDim2.new(target.HP.Value/target.MaxHP.Value,0,1,0)}):Play()
end
end
MTrack.Stopped:Wait()
mining = false
end
end)
Idk if this will work but maybe you could do :Destroy and then give them the money afterwards like player.leaderstats.Cash = player.leaderstats.Cash + 10
I believe i know the issue. It could be that the value isn’t equaled to one when you mine it so it never fires the functions. So instead you want to check if it’s equal to 1 or under.
Instead of doing
You should use this, it will check if the 1 is equal to or greater than the HP value
But the money is still being added which proves that it is running. The issue started occurring when I added the game.ReplicatedStorage.REs.Mined:FireServer(target.MaxHP.Value, target.Name) part. So I think it might be something related to that.
if target:FindFirstChild("HP") and target:FindFirstChild("MaxHP") then
if target:FindFirstChild("HP").Value == 1 then
task.spawn(RespawnTargetOre, target)
end
target:FindFirstChild("HP").Value -= 1
if not target:FindFirstChild("HealthBar") then
local HBar = game.ReplicatedStorage.HealthBar:Clone()
HBar.Parent = target
end
TS:Create(target.HealthBar.Frame.Frame, TweenInfo.new(0.25, Enum.EasingStyle.Quad), {Size = UDim2.new(target.HP.Value/target.MaxHP.Value,0,1,0)}):Play()
end
game.ReplicatedStorage.REs.Mined.OnServerEvent:Connect(function(plr, amt, ore)
if ore == "Coal" then
if amt == 2 then
plr.leaderstats.Cash.Value += 2
else
plr:Kick("Exploiting")
warn(plr.Name.." has been kicked for exploiting.")
end
elseif ore == "Iron" then
if amt == 5 then
plr.leaderstats.Cash.Value += 5
else
plr:Kick("Exploiting")
warn(plr.Name.." has been kicked for exploiting.")
end
elseif ore == "Gold" then
if amt == 10 then
plr.leaderstats.Cash.Value += 10
else
plr:Kick("Exploiting")
warn(plr.Name.." has been kicked for exploiting.")
end
elseif ore == "Diamond" then
if amt == 20 then
plr.leaderstats.Cash.Value += 20
else
plr:Kick("Exploiting")
warn(plr.Name.." has been kicked for exploiting.")
end
else
plr:Kick("Exploiting")
warn(plr.Name.." has been kicked for exploiting.")
end
end)```