Ok so for some context, I’m making a mining game and while I was trying to subtract an ore health when reworking my mining system I encountered a issue when subtracting the ore’s health by the damage of the pickaxe.
This probably sounds stupid but I’ve tried like 6 different configurations and tried like 3 different dev forum posts, It’s probably something stupid or I didn’t understand the dev forum posts.
Script:
game.ReplicatedStorage.Remote_Events.BE342.OnServerEvent:Connect(function(Player, Pickaxe, part)
local Total_Damage = Pickaxe.Stats.Base_Damage.Value
local Part = part
local Part_Health = Part.Stats.Health
local Granted = Part.Stats.Granted
local Granted_Type = Part.Stats.Granted_Type
for i,v in pairs(Player.Ores_Folder:GetChildren()) do
if v.Name == "Coal" and Granted_Type == "Coal" then
Part.Stats.Health.Value = Part_Health.Value - Total_Damage --Not subtracting
if Part_Health.Value <= 0 then
print("Below 0")
Player.Ores_Folder.Coal.Value += Granted.Value
Part.Parent = game.ServerStorage
wait(5)
Part.Parent = workspace
end
end
end
end)
Video:
(Sorry about the poor quality on the video, I just uploaded it)
The local piece of the script is just the mining script, but sure!
local Player = game.Players.LocalPlayer
local Swing_ANIM = script.Parent.Swing
local Coll_SERV = game:GetService("CollectionService")
local Debounce = false
local Cooldown = script.Parent.Stats.Cooldown.Value
script.Parent.Activated:Connect(function()
if Debounce == false then
Debounce = true
local Character = Player.Character
local Humanoid = Character:FindFirstChild("Humanoid")
local Animator = Humanoid:FindFirstChild("Animator")
local LoadedSwing = Animator:LoadAnimation(Swing_ANIM)
local Hitbox = Instance.new("Part")
Hitbox.Name = "Hitbox"
Hitbox.Position = script.Parent.Pickaxe.Hitbox_PRT.Position
Hitbox.Size = Vector3.new(5, 5, 5)
Hitbox.Transparency = 1
Hitbox.CanCollide = false
Hitbox.Anchored = true
Hitbox.Parent = Player.Character
wait(.1)
local OverlapPARA_NEW = OverlapParams.new()
OverlapPARA_NEW.FilterDescendantsInstances = {Character}
OverlapPARA_NEW.FilterType = Enum.RaycastFilterType.Exclude
for i,part in pairs(workspace:GetPartsInPart(Hitbox,OverlapPARA_NEW)) do
if part:HasTag("Breakable") then
if part:HasTag("Pickaxe_Mined") then
script.Parent.Strike_Sound:Play()
if Hitbox.Parent:FindFirstChildOfClass("Tool"):HasTag("Pickaxe") then
local Pickaxe = Hitbox.Parent:FindFirstChildOfClass("Tool")
if Pickaxe.Stats.Level.Value >= part.Stats.Level.Value then
game.ReplicatedStorage.Remote_Events.BE342:FireServer(Pickaxe, part)
end
end
end
end
end
LoadedSwing:Play()
wait(.1)
LoadedSwing:Stop()
Hitbox:Destroy()
task.wait(Cooldown)
Debounce = false
end
end)
game.ReplicatedStorage.Remote_Events.BE342.OnServerEvent:Connect(function(Player, Pickaxe, part)
local Total_Damage = Pickaxe.Stats.Base_Damage.Value
local Part = part
local Part_Health = Part.Stats.Health
local Granted = Part.Stats.Granted
local Granted_Type = Part.Stats.Granted_Type
if Part.Name == "Coal" and Granted_Type.Value == "Coal" then
Part.Stats.Health.Value = Part_Health.Value - Total_Damage
if Part_Health.Value <= 0 then
print("Below 0")
Player.Ores_Folder.Coal.Value += Granted.Value
Part.Parent = game.ServerStorage
wait(5)
Part.Parent = workspace
end
end
end)
I added .Value here Granted_Type.Value
And also removed for loop because it’s not needed here