Why is the transparency of the parts in my model only changing once and never agaim?

I’m trying to make a mining system that awards the player currency upon mining an ore, but, the transparency of the ore seems to only be working once. Might there be a solution to this?

Serverscript that only runs once.

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


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

i dont see what the purpose of the wait(2) is what if you remove it?

The wait(2) is there as a way to limit how many times the model goes transparent. Since if it wasn’t there, the ore would vanish in an instant and I don’t want this to happen

the ore wouldnt vanish in an instant. it depends on how fast the event gets called. the wait just delays the code from going through the model

This should work, although I haven’t tested it.

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 hum then
local pickaxe = char:FindFirstChild(“Pickaxe”)
if pickaxe then
if debounce == false then
debounce = true
for _, v in ipairs(Ore:GetChildren()) do
if v:IsA(“BasePart”) and v.Name ~= “Hitbox” then
v.Transparency = OreTransparency + 0.25
wait(2)
debounce = false
end
end
end
end
end
end)

I have removed the wait, and the transparency is still only changed once unfortunately.

I’d still like a possible answer to this question, as I haven’t figured this out yet…

Try inserting prints into the code to see what runs, I’d also like to see how you’re calling the event and why you’re using a remote event? I’d imagine you’d detect the touch on the server and use a bindable event instead of client sided detection then using remotes?

Sure. I’ll show you where the remote event is connected to! In fact, there’s four which call the same remote event. But, I’ll just show you both.

local IronOre = game.Workspace.IronOre
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Hitbox = script.Parent:WaitForChild("Hitbox")
local replicatedStorage = game:GetService("ReplicatedStorage")
local OreTouchedEvent = replicatedStorage.OreTouchedEvent

Hitbox.Touched:Connect(function(player)
	OreTouchedEvent:FireServer(IronOre)
end)
local GoldOre = game.Workspace.GoldOre
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Hitbox = script.Parent:WaitForChild("Hitbox")
local replicatedStorage = game:GetService("ReplicatedStorage")
local OreTouchedEvent = replicatedStorage.OreTouchedEvent

Hitbox.Touched:Connect(function(player)
	OreTouchedEvent:FireServer(GoldOre)
end)

These are both localscripts found within the IronOre and GoldOre models respectively

Are the hitboxes touch once?
Char Limit

They’re supposed to be able to be touched multiple times, and it works as intended up until

v.Transparency = OreTransparency + 0.25

I don’t think you should put that script in the ServerScriptStorage. That’s my guess and I do not exactly know

What are you using for these hitboxes? Also when I say hit once, i mean if the same part touches the hitbox multiple times it ignores its touches besides for the first hit.

As you can see here, the hitbox is a basepart
image

And uh… It does run I can assure you that!
image

image

That’s pretty strange. Try changing V.Transparency = OreTransparency + 0.25 to V.Transparency += 0.25? Other than that I would seriously recommend switching from remote events to bindable events and having everything done on the server.

image
Very odd.

V.Transparency += 0.25 not OreTransparency

I’m unsure as to how bindable events work to be honest with you, but I’ll try to figure them out once this issue is rectified