Int Value + Script not reading properly

I’m trying to make a rock mesh disappear after you click it 30 times and break into smaller pieces when it reaches 0. Problem however is that the counter for the health of the rock wont update and neither will the effects of the “breakage” happen when the int value reaches 0. I’m not sure if I’m doing something wrong or whether it’s a studio bug but I’d really like to know.

Updater script:

local After = script.Parent.After

local RockHealth = script.Parent.Health.Value

while wait() do

script.Parent.Parent.bg.g.t.Text = script.Parent.Health.Value.. ("/25")

end

MainManager script:

local RockHealth = script.Parent.Health.Value

local clickDetector = script.Parent.ClickDetector

clickDetector.MouseHoverEnter:Connect(function()
	script.Parent.Transparency = 0.1
	task.wait(0.02)
	script.Parent.Transparency = 0.2
	task.wait(0.02)
	script.Parent.Transparency = 0.3
	task.wait(0.02)
	script.Parent.Transparency = 0.4
	task.wait(0.02)
	script.Parent.Transparency = 0.5
	task.wait(0.02)
	script.Parent.Transparency = 0.6
end)

clickDetector.MouseHoverLeave:Connect(function()
	script.Parent.Transparency = 0.5
	task.wait(0.02)
	script.Parent.Transparency = 0.4
	task.wait(0.02)
	script.Parent.Transparency = 0.3
	task.wait(0.02)
	script.Parent.Transparency = 0.2
	task.wait(0.02)
	script.Parent.Transparency = 0.1
	task.wait(0.02)
	script.Parent.Transparency = 0
end)

clickDetector.MouseClick:Connect(function()
	RockHealth = RockHealth - 1
	print(RockHealth)
	
	script.Parent.Transparency = 0.5
	task.wait(0.02)
	script.Parent.Transparency = 0.4
	task.wait(0.02)
	script.Parent.Transparency = 0.3
	task.wait(0.02)
	script.Parent.Transparency = 0.2
	task.wait(0.02)
	script.Parent.Transparency = 0.1
	task.wait(0.02)
	script.Parent.Transparency = 0.6
	
	script.Parent.ParticleEmitter.Enabled = true
	task.wait(0.3)
	script.Parent.ParticleEmitter.Enabled = false
end)

local After = script.Parent.After

while true do
	task.wait()
if script.Parent.Health.Value < 1 then
	if RockHealth < 1 then
		script.Parent.Transparency = 1
		script.Parent.CanCollide = false
		script.Parent.ClickDetector.MaxActivationDistance = 0

		After.Stone1.Transparency = 0
		After.Stone2.Transparency = 0
		After.Stone3.Transparency = 0
		After.Stone4.Transparency = 0

		After.Stone1.ProximityPrompt.Enabled = true
		After.Stone2.ProximityPrompt.Enabled = true
		After.Stone3.ProximityPrompt.Enabled = true
		After.Stone4.ProximityPrompt.Enabled = true
		end
	end
end

image

Rewrote the script slightly different and it works a-ok again.

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