-
What do you want to achieve? Keep it simple and clear!
Topic could be a bit complicated, so i’m making a hitbox based mining system which communicated between server/client -
What is the issue? Include screenshots / videos if possible!
exactly when i tested it with 2 players, i figured out what only one player can mine in same time, the other one can’t
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
well i have no idea how that happened
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
Full code of script:
local ObjectHandler = workspace.Events.ObjectHandler
local PlayerManager = require(script.Parent.PlayerManager)
local TweenService = game:GetService("TweenService")
local radius = 20
local action = ""
...
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
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") ~= true 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")
Tool:SetAttribute("inUse", false)
player.Character.Humanoid.WalkSpeed = 16
end
end
local calculate = target.Parent.Rock:GetAttribute("CurrentHealth") - DPC
target.Parent.Rock:SetAttribute("CurrentHealth", calculate)
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)