Problem with changing text to a numbervalue

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?..

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 = tostring(hv.Value) .. '%'
end)

there is an error saying this :
image

Remove the value. 333333333333333333333

That’s incorrect, do:

local health = script.Parent.Parent.Parent.Parent.Health
local mining = game:GetService("ReplicatedStorage").Mining

script.Parent.Text = "100%"

health:GetPropertyChangedSignal('Value'):Connect(function()
    script.Parent.Text = tostring(health.Value) .. '%'
end)
1 Like

robloxapp-20231010-2044197.wmv (794.5 KB)
the text still wont change

Then it has to do with the system that handles the hitboxes for the mining, try using a print to debug.

image
i already used one

You do the hitbox handle on the client side?

i think… so
character limit 30

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.

how would i do it?

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

I can’t really redo your code so that it would work on the server-side.

oh… alr ty anyway
character limit

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

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.