So I got a LocalScript which removes the hp of a crystal:
local tool = script.Parent.Parent
local playersInZone = require(game.ReplicatedStorage:WaitForChild("Zones").Crystals.Crystal1second)
local re = game.ReplicatedStorage:WaitForChild("Zones").Crystals.SwingSound
local re2 = game.ReplicatedStorage:WaitForChild("Zones").Crystals.HitSound
local re3 = game.ReplicatedStorage:WaitForChild("Zones").Crystals.BreakSound
local PickaxeDamageBoost = game.Players.LocalPlayer.Stats.PickaxeDamageBoost
local playergui = game.Players.LocalPlayer.PlayerGui
local red = playergui.CrystalButtons.ScreenGui.HPs.HP1.Red
local regenerate = playergui.CrystalButtons.ScreenGui.HPs.HP1.Regenerate
local isActivated = false
local PickaxeSpeed = game.Players.LocalPlayer.Stats.PickaxeSpeed
local PickaxeDmg = game.Players.LocalPlayer.Stats.PickaxeDmg.Value
local waittime = 0.54 - (0.54*PickaxeSpeed.Value*0.03)
local speedtime = 0.65 + (0.65*PickaxeSpeed.Value*0.03)
tool.Activated:Connect(function()
for _, player in pairs(playersInZone) do
local HP = game.Workspace.Crystals.HPs.HP1
if HP.Value >= 1 then
if not isActivated then
isActivated = true
local animationId = "rbxassetid://13862469344"
local Humanoid = script.Parent.Parent.Parent.Humanoid
local animation = Instance.new("Animation", Humanoid)
animation.AnimationId = animationId
local Animation = Humanoid.Animator:LoadAnimation(animation)
Animation.Looped = false
re:FireServer()
Animation:Play()
Animation:AdjustSpeed(speedtime)
wait(waittime)
Animation:Stop()
if PickaxeDmg < HP.Value then
re2:FireServer()
end
HP.Value -= PickaxeDmg --Removing the HP
if HP.Value < 1 then
red.Visible = false
regenerate.Visible = true
re3:FireServer()
end
isActivated = false
end
end
end
end)
And I got a ServerScript that gives a pickaxe more damage (it’s a serverscript so datasave can save the value):
local RS = game:GetService("ReplicatedStorage")
local PickaxeDamageButton = RS.UpgradeButtons.Crystal:WaitForChild("PickaxeDamageButton")
PickaxeDamageButton.OnServerEvent:Connect(function(player)
local Crystal = player.Stats.Crystal
local PickaxeDamageBoost = player.Stats.PickaxeDamageBoost
local PickaxeDmg = player.Stats.PickaxeDmg
if PickaxeDamageBoost.Value >= 0 and PickaxeDamageBoost.Value < 2 then
if Crystal.Value >= 10 then
Crystal.Value -=10
PickaxeDamageBoost.Value +=1
PickaxeDmg.Value +=1 --Adding damage
end
elseif PickaxeDamageBoost.Value >= 2 and PickaxeDamageBoost.Value < 10 then
if Crystal.Value >= 15 then
Crystal.Value -=15
PickaxeDamageBoost.Value +=1
PickaxeDmg.Value +=1 --Adding damage
end
elseif PickaxeDamageBoost.Value >= 10 and PickaxeDamageBoost.Value < 12 then
if Crystal.Value >= 100 then
Crystal.Value -=100
PickaxeDamageBoost.Value +=1
PickaxeDmg.Value +=6 --Adding damage
end
elseif PickaxeDamageBoost.Value >= 12 and PickaxeDamageBoost.Value < 20 then
if Crystal.Value >= 150 then
Crystal.Value -=150
PickaxeDamageBoost.Value +=1
PickaxeDmg.Value +=6 --Adding damage
end
end
end)
The problem is when the PickaxeDmg value increases I still do the same amount of damage to a crystal. If I rejoin then it works. How can I fix this?