Why is my model disappearing quicker than I want it to?

I’ve been trying to find out why the transparency of my model is changing very rapidly. I have yet to find a solution to this, as I’ve tried everything I could think of. Getting some help with this would be greatly appreciated. Below, you’ll find the scripts that are causing this sudden transparency shift.

Localscript

local AzureOre = game.Workspace.AzureOre
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Hitbox = script.Parent:WaitForChild("Hitbox")
local replicatedStorage = game:GetService("ReplicatedStorage")
local OreTouchedEvent = replicatedStorage.OreTouchedEvent
local Character = Player.Character or Player.CharacterAdded:Wait()
local Pickaxe = Character:WaitForChild("Pickaxe")
local Handle = Pickaxe:WaitForChild("Handle")
local Count = 0


Hitbox.Touched:Connect(function(player)
	local function Check()
		if Handle:GetAttributeChangedSignal("Activated") then
		else return end
		Count += 1
		local Cast = workspace:Raycast(Handle.Position, Handle.CFrame.LookVector * 2)
		if Cast then
			if Cast.Instance.Name ~= AzureOre.Name then return end
		else
			return
		end
	end

	repeat task.wait(1) Check() until Count == 5
	OreTouchedEvent:FireServer(AzureOre)
	Count = 0
end)

Tool script

local Tool = script.Parent
local Handle = Tool.Handle

Tool.Activated:Connect(function()
	Handle:SetAttribute("Activated")
end)

Tool.Deactivated:Connect(function()
	Handle:SetAttribute("Deactivated")
end)

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

Here’s a video of the ore disappearing too quickly.
https://gyazo.com/3622e98873cfaf08838d45151770dc58

I’ve tried a lot of things to make this work, however, I’m still struggling to figure this out…

1 Like

Just add a little task.wait(1) after setting transparency.

for _, v  in Ore:GetChildren() do
				if v:IsA("BasePart") and v.Name ~= "Hitbox" then
					v.Transparency += 0.25
					task.wait(1)
				end
			end			

Also your script is well… interesting… I think it requires a whole other post to explain it.

The problem here is that it goes over every part, setting the transparency to + 0.25, and in order to properly function i wish for it to go over every part and change the transparency of all the parts to 0.25 as fast as possible, but only once per touched event.

image

You should put the above the event and outside of it, not only does it harm readability, but you’re literally creating a whole new function each time the event fires.

wait() is also deprecated, please use task.wait() as it’s the new version and it has more benefits.

you don’t need to use pairs/ipairs anymore, you can simply just write “in”, not only is this also again better for readability, but it’s faster to loop through the table.

The only reason you’d need to use ipairs is if you don’t want to keep looping through if there is a nil object, which I can’t say many times i’ve had to do this.

Ohhhh, this is because when you touch a basepart in roblox. Multiple parts are touching it and it fires very quickly. I suggest you learn about something called “debouncing”

Also learn about offsetting and vectors for that over the part stuff.

So something such as this?

local function Check()
	Count += 1
	local Cast = workspace:Raycast(Handle.Position, Handle.CFrame.LookVector * 2)
	if Cast then
		if Cast.Instance.Name ~= AzureOre.Name then return end
	else
		repeat task.wait(1) Check() until Count == 5
		OreTouchedEvent:FireServer(AzureOre)
		Count = 0
	end
end

Hitbox.Touched:Connect(Check)

Yes this is much better, great job. And again, learn about debouncing and vectors/offsetting for what you’re trying to do.

1 Like

Weirdly enough, it doesn’t seem to work as I intend it to

1 Like

Nothing occurs when touching the model with a pickaxe

1 Like

.Touched is very inefficient for hitboxes and you’d see that is very apparent in the actual server of your game if you had many players, if you want more of an accurate hitbox. I suggest you use raycasting/magnitude or :GetPartsBoundsInBox(), which are more accurate in their detections and would be better as a hitbox.