Code not working?

There is something wrong with my code, it doesn’t show any errors though. One im trying to do is that when the pickaxe hits the rock there is a billboard gui above it that adds the number by 20, My 2 codes are listed below, I am also aware that there is no debounce on the pickaxe so that it may add the number by 2 or 3 more times but tthe number just stays the same.

Pickaxe code:

	local Ore = part.Parent:FindFirstChild("RockOre")
	if Ore then
		local OreValue = Ore.Parent.BillboardGui.Value.Value
		OreValue = OreValue + 20

		print("Mined!")
	end
end


script.Parent.Touched:Connect(Mine)

Ore code


while true do
	local Value = script.Parent.Value.Value  -- get the current value

	script.Parent.TextLabel.Text = ("%" .. Value)

	wait(debounceTime)  -- pause the loop for the debounce time
end

the print functions do work in the pickaxe code btw.

1 Like

You aren’t actually changing the value of the Billboard here. What you are doing is cloning the value, and then later overriding the variable.

See the difference in the example below:

local tab = {value = 1}

tab.value += 1 --increment the value INSIDE the table

local value = tab.value
value += 1 --increment the variable itself

So to fix your code, you have to index for what needs to be changed in the statement itself:

	if Ore then
		local OreValue = Ore.Parent.BillboardGui.Value
		OreValue.Value += 20
2 Likes

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