local health = script.Parent.Parent.Parent.Parent.Health
local hv = health.Value
local mining = game:GetService("ReplicatedStorage").Mining
script.Parent.Text = "100%"
hv.Changed:Connect(function()
script.Parent.Text = hv..'%'
end)
How would i make the text update to the number value?..
I suggest you do it in the server-side, otherwise there would be a lot of exploits for your game, and you wouldn’t be able to send data to the server for the other players.
local pickaxe = script.Parent
local canmine = pickaxe.CanMine
local anim = pickaxe.Animation
local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character
local animtrack
local humanoid
local ismining = false
local isactive = false
local animplaying = false
local pickaxehitbox = pickaxe.Pickaxepart.PickaxeHitbox
local mining = game:GetService("ReplicatedStorage").Mining
local function CharAdded(char)
character = char
humanoid = character:WaitForChild("Humanoid")
animtrack = humanoid:LoadAnimation(anim)
end
if player.Character then CharAdded(player.Character) end
player.CharacterAdded:Connect(CharAdded)
canmine.Value = true
pickaxe.Activated:Connect(function()
if canmine.Value == true and animplaying == false then
print("activated")
isactive = true
animtrack:Play()
canmine.Value = false
animplaying = true
wait(3)
animplaying = false
pickaxehitbox.Touched:Connect(function(hit)
if ismining == false then
if hit.Name == "Hitbox" or hit.Parent == "Rocks" then
print("mining")
mining:FireServer()
ismining = true
local health = hit.Parent.Health
if health:isA("NumberValue") then
print(health.Value)
health.Value -= 1
end
if ismining == true then
wait(1)
ismining = false
end
end
end
end)
task.wait(1)
canmine.Value = true
end
end)
if isactive == true then
wait(1)
isactive = false
end
Try this (works if pickaxe isn’t parented to anything else originally and is cloned directly into player):
local pickaxe = script.Parent
local canmine = pickaxe.CanMine
local anim = pickaxe.Animation
local players = game:GetService("Players")
local player = players:GetPlayerFromCharacter(pickaxe.Parent) -- get player if tool is equipped
local character
local animtrack
local humanoid
local ismining = false
local isactive = false
local animplaying = false
local pickaxehitbox = pickaxe.Pickaxepart.PickaxeHitbox
local mining = game:GetService("ReplicatedStorage").Mining
if pickaxe.Parent:IsA("Backpack") then -- checks if tool is in backpack
player = pickaxe.Parent.Parent -- since backpack is always a child of a player, we get player from the backpack's parent
end
local function CharAdded(char)
character = char
humanoid = character:WaitForChild("Humanoid")
animtrack = humanoid:LoadAnimation(anim)
end
if player.Character then CharAdded(player.Character) end
player.CharacterAdded:Connect(CharAdded)
-- the rest of code