How would I detect if all parts within a model have become transparent?

Due to issues involving the script that I’ve made, I’m trying another approach. I wish to know when all of the parts have gained a transparency value of 0.25 and once this happens, end the script only for it to repeat upon the activation of a tool. Below you’ll find the code that I already have.

Serverscript

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local OreTouchedEvent = ReplicatedStorage.OreTouchedEvent
local OreTransparency = 0
local debounce = false

OreTouchedEvent.OnServerEvent:Connect(function(player, Ore)
	local char = player.Character
	local hum = char:FindFirstChildOfClass("Humanoid")
	if not debounce then
	if hum then
		local pickaxe = char:FindFirstChild("Pickaxe")
		if pickaxe then
			for _, v  in(Ore:GetChildren()) do
				if v:IsA("BasePart") and v.Name ~= "Hitbox" then
					v.Transparency += 0.25
					
					
					end
				end
			end				
		end
	end
end)

I’ve tried to detect using a for do, however, this doesn’t work and is spitting out an error.

if v:IsA("BasePart") and v.Name ~= "Hitbox" then
					v.Transparency += 0.25
						for v in pairs(Ore:GetChildren()) do
							if v.Transparency == 0.25 then
1 Like

What are you trying to do exactly? Like why are you using the transparency? And why does it have to be transparency?

1 Like

Because I’m creating a mining system, and with this, capability to mine ore with a pickaxe. Transparency is used as a progress indicator as to how close the ore is from being mined and currency granted.

1 Like

I’ve been having issues with the ore vanishing instantly, as shown below
https://gyazo.com/3622e98873cfaf08838d45151770dc58

1 Like

Did you set debounce to true after touching it?

OreTouchedEvent.OnServerEvent:Connect(function(player, Ore)
	local char = player.Character
	local hum = char:FindFirstChildOfClass("Humanoid")
	if not debounce then
	if hum then
		local pickaxe = char:FindFirstChild("Pickaxe")
		if pickaxe then
			for _, v  in(Ore:GetChildren()) do
				if v:IsA("BasePart") and v.Name ~= "Hitbox" then
					v.Transparency += 0.25
					
					
					end
				end
			end		

			debounce = true

			task.wait(Your tool's cooldown time)
			debounce = false
		end
	end
end)

You’re already increasing the transparency of all the baseparts whose name is not “Hitbox” by another 0.25, all at once with the loop

2 Likes

This has seemingly solved my problem. Thank you!

1 Like

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