It instantly breaks and loops regenerating of ore + players can’t mine in same time from first click not on regenerate
I figured something like that would happen. I really don’t know why your cooldown function isn’t working, it’s probably me overlooking something. Remove all the other coroutines other than the cooldown one, and I can try to find the issue with it.
function Cooldown(player, target)
local Timer = target.Parent.Rock:GetAttribute("Delay")
local GameGUI = player.PlayerGui.GameGUI
GameGUI.Reload.Visible = true
local cooldownThread = coroutine.create(function()
while Timer > 0 do
GameGUI.Reload.Bar.ProgressBar:TweenSize(UDim2.new(Timer/target.Parent.Rock:GetAttribute("Delay"),0,1,0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quad, 0.1, true)
Timer -= 0.1
task.wait(0.1)
end
end)
coroutine.resume(cooldownThread)
if Timer <= 0 then
GameGUI.Reload.Visible = false
end
end
You mean that or
local cooldownThread = coroutine.create(function()
Cooldown(player, target)
end)
coroutine.resume(cooldownThread)
?
EDIT: If you need i can give you a model of that minining system or .rbxl file
You can try both if you would like, and about the rbxl if you want to, sure but I think it would be good for you to try to solve some of this yourself as well. But try both of the solutions separately to see if there’s a difference.
You’re right about the debounce being an issue, my bad for not understanding what you meant lol. I’ll look into it more and see if I can fix it.
@PhantomGame_Youtube, I believe I fully fixed your issue! You didn’t need to use a debounce. Instead, you should have used your “inUse” attribute as a debounce for each player, since it has a seperate value for each player’s tool. Here’s the fixed code, you could also download the rbxl I attached:
local ObjectHandler = workspace.Events.ObjectHandler
local PlayerManager = require(script.Parent.PlayerManager)
local TweenService = game:GetService("TweenService")
local Debounce = false
local radius = 20
local action = ""
local function Suffix(Number, Precision)
local Suffixes = {
"", " K"," M", " B", " T",
" Qd", " Qn", " Sx", " Sp",
" Oc", " No", " De", " Un",
" Tr", " Qud", " Qun", " Sxd",
" Spd", " Ocd", " Nod", " Vg",
" UVg"," DVg"," TVg"," QdVg",
" QnVg"," SxVg"," SpVg"," OcVg",
" NoVg"," Tg"," UTg"," DTg"," TTg",
" QdTg"," QnTg"," SxTg"," SpTg"," OcTg",
" NoTg"," qg"," Uqg"," Dqg"," Tqg"," Qdqg",
" Qnqg"," Sxqg"," Spqg"," Ocqg"," Noqg",
" Qg"," UQg"," DQg"," TQg"," QdQg"," QnQg",
" SxQg"," SpQg"," OcQg"," NoQg"," sg"," Usg",
" Dsg"," Tsg"," Qdsg"," Qnsg"," Sxsg"," Spsg",
" Ocsg","Nosg"," Sg"," USg"," DSg"," TSg",
" QdSg"," QnSg"," SxSg"," SpSg"," OcSg"," NoSg",
" Og"," UOg"," DOg"," TOg"," QdOg"," QnOg"," SxOg",
" SpOg"," OcOg"," NoOg"," Ng"," UNg"," DNg"," TNg",
" QdNg"," QnNg"," SxNg"," SpNg"," OcNg"," NoNg"
}
local Index = math.floor(math.log10(Number) / 3)
if Index < 0 then
Index = 0
end
local Suffix = Suffixes[Index + 1]
Number = Number / (10 ^ (3 * Index))
Number = tostring(math.floor(Number * 10 ^ Precision) / 10 ^ Precision)
return Number .. Suffix
end
game:GetService("Players").PlayerAdded:Connect(function(plr)
PlayerManager.Start()
end)
function Animate(Player)
local aTable = {
[1] = 9981038826,
[2] = 9981055504
}
local pChar = Player.Character
local random = math.random(1,2)
local CurrentAnimation = Instance.new("Animation")
CurrentAnimation.AnimationId = "rbxassetid://"..aTable[random]
local LoadAnim = pChar.Humanoid:LoadAnimation(CurrentAnimation)
LoadAnim:Play()
end
function Cooldown(player, target)
local Timer = target.Parent.Rock:GetAttribute("Delay")
local GameGUI = player.PlayerGui.GameGUI
GameGUI.Reload.Visible = true
while Timer > 0 do
GameGUI.Reload.Bar.ProgressBar:TweenSize(UDim2.new(Timer/target.Parent.Rock:GetAttribute("Delay"),0,1,0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quad, 0.1, true)
Timer -= 0.1
task.wait(0.1)
end
if Timer <= 0 then
GameGUI.Reload.Visible = false
local Tool = player.Character.WoodPick
Tool:SetAttribute("inUse", false)
end
end
local function Mine(player, target)
if target and target.Parent and target.Parent.Rock then
if target.Parent.Rock:GetAttribute("isRegenerating") == false then
local Tool = player.Character.WoodPick
player.Character.Humanoid.WalkSpeed = 6
ObjectHandler:FireClient(player, target, "Change")
local DPC = Tool:GetAttribute("DPC")
local Value = target.Parent.Rock:GetAttribute("Value")
target.Parent.Rock:SetAttribute("Owner", player.Name)
while target.Parent.Rock:GetAttribute("CurrentHealth") > 0 and Tool:GetAttribute("inUse") == false and action == "Start" do
Tool:SetAttribute("inUse", true)
Animate(player)
local distance = (target.Position - player.Character.HumanoidRootPart.Position).Magnitude
if distance > radius then
action = "Override"
if target then
ObjectHandler:FireClient(player, target, "Disable")
target.Parent.Rock:SetAttribute("Owner", "Empty")
player.Character.Humanoid.WalkSpeed = 16
end
end
local calculate = target.Parent.Rock:GetAttribute("CurrentHealth") - DPC
target.Parent.Rock:SetAttribute("CurrentHealth", calculate)
Tool:SetAttribute("inUse", true)
if target.Parent.Rock:GetAttribute("CurrentHealth") ~= 0 then
Cooldown(player, target)
end
end
if target.Parent.Rock:GetAttribute("CurrentHealth") == 0 then
player.Character.Humanoid.WalkSpeed = 16
ObjectHandler:FireClient(player, target, "Disable")
Tool:SetAttribute("inUse", false)
PlayerManager.SetCoal(player, PlayerManager.GetCoal(player) + Value)
target.Parent.Rock:SetAttribute("isRegenerating", true)
Regenerate(target)
end
end
end
end
function Regenerate(target)
local info = TweenInfo.new(
2, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut, 0
)
local tween = TweenService:Create(target.Parent.Rock, info, {Size = Vector3.new(0.002,0.001,0.002)})
local adTween = TweenService:Create(target.Parent.Union, info, {Size = Vector3.new(0.002,0.001,0.002)})
tween:Play()
adTween:Play()
tween.Completed:Connect(function()
target.Parent.Rock.Transparency = 1
target.Parent.Rock.CanCollide = false
target.Parent.Union.Transparency = 1
target.Parent.Union.CanCollide = false
local regenTimer = math.random(5, 6)
Timer(regenTimer, target)
target.Parent.Rock.Transparency = 0
target.Parent.Rock.CanCollide = true
target.Parent.Union.Transparency = 0
target.Parent.Union.CanCollide = true
local reverseTween = TweenService:Create(target.Parent.Rock, info, {Size = Vector3.new(6.3, 3.15, 6.3)})
local adReverseTween = TweenService:Create(target.Parent.Union, info, {Size = Vector3.new(3.5, 6.5, 6.4)})
reverseTween:Play()
adReverseTween:Play()
reverseTween.Completed:Connect(function()
target.Parent.Rock:SetAttribute("isRegenerating", false)
target.Parent.Rock:SetAttribute("Owner", "Empty")
end)
end)
end
function Timer(timer, target)
while timer > 0 do
timer -= 0.1
target.Parent.Rock.Settings.Regenerate.Visible = true
target.Parent.Rock.Settings.Default.Visible = false
if timer > 0 then
target.Parent.Rock.Settings.Regenerate.MainFrame:WaitForChild("RegLabel").Text = Suffix(timer, 2).."s" -- 1.05
end
task.wait(0.1)
end
if timer <= 0 then
target.Parent.Rock.Settings.Regenerate.Visible = false
target.Parent.Rock.Settings.Default.Visible = true
target.Parent.Rock:SetAttribute("CurrentHealth", target.Parent.Rock:GetAttribute("MaxHealth"))
end
end
ObjectHandler.OnServerEvent:Connect(function(player, target, Action)
if Action == "Start" then
action = "Start"
Mine(player, target)
elseif Action == "Override" then
action = "Override"
if target then
player.Character.Humanoid.WalkSpeed = 16
if player.Character:FindFirstChild("WoodPick") then
player.Character:FindFirstChild("WoodPick"):SetAttribute("inUse", false)
elseif player.Backpack:FindFirstChild("WoodPick") then
player.Backpack:FindFirstChild("WoodPick"):SetAttribute("inUse", false)
end
target.Parent.Rock:SetAttribute("Owner", "Empty")
end
end
end)
miningfixed.rbxl (82.9 KB)
Have a good day, and good luck with the rest of your project!
I have no idea how you fixed it with in use attribute before, because when i used it gave me same problem like before, thank you
Think of the attribute as a debounce, and update it just like you would with a regular debounce variable. If you would like, I can tell you exactly what I changed so you can learn from it.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.