Why is my part's transparency jittering?

Hello!

I have a script to fire a RemoteEvent which makes the part gradually disappear for the local player, however the transparency on here is jittering.

Video (potential epilepsy warning)

Here’s my script that makes it disappear:

function variables(name, part, functionName, sendscript)
	if functionName == "disappear" then
	
		for t = 0, 1, 0.05 do
			part.Transparency = t
			wait()
		end
		part.CanCollide = false
		wait(5)
		part.CanCollide = true
		part.Transparency = 0
	end
end

game.ReplicatedStorage.BrickProperties.OnClientEvent:Connect(variables)

In the serverscript, I’m using a .Touched event to fire the client.

1 Like

you need a debounce in the server script when its touched, the Touched event is firing the remote event like 100 times a second

1 Like

If I did this, wouldn’t it limit the amount of times it can be fired for all users?

For example, say 5 people are on the level, wouldn’t it just disappear for one user?

This is server-sided correct? Debounce is only used so a piece of code can’t be executed super fast. It shouldn’t mess up any view of the parts transparency for users.

Edit: I see you are firing to the client, why not make it full server?

1 Like

If one person touches it, they have a time limit to make it to the other side before it disappears entirely, which could mess up other players if, say, one person is just standing on it and having it repeatedly disappear.

what it sounds like is you should make this all client-sided (you only need one localScript). Try this:

local part = workspace.lolPart
local debounce = true

part.Touched:Connect(function(touchingPart)
local touchingPlayer = game:GetService("Players"):GetPlayerFromCharacter(touchingPart.Parent) 
if debounce == true and touchingPlayer and touchingPlayer == game:GetService("Players").LocalPlayer then
debounce = false
		for t = 0, 1, 0.05 do
			part.Transparency = t
			game:GetService("RunService").Heartbeat:Wait()
		end
		part.CanCollide = false
		wait(5)
debounce = true
		part.CanCollide = true
		part.Transparency = 0
end
end)

1 Like

That would work, the downside being having to make an individual name for each part, however since there are stages, it probably could work relatively easily with prefixes and suffixes.

Also, out of curiosity, what is HeartBeat?

actually, you can make it for many parts. Try this:

local folderContainingParts = workspace.lolFolder
local debounce = true

for _, v in pairs(folderContainingParts:GetChildren()) do
v.Touched:Connect(function(touchingPart)
local touchingPlayer = game:GetService("Players"):GetPlayerFromCharacter(touchingPart.Parent) 
if debounce == true and touchingPlayer and touchingPlayer == game:GetService("Players").LocalPlayer then
debounce = false
		for t = 0, 1, 0.05 do
			v.Transparency = t
			game:GetService("RunService").Heartbeat:Wait()
		end
		v.CanCollide = false
		wait(5)
debounce = true
		v.CanCollide = true
		v.Transparency = 0
end
end)
end

also, heartbeat is an event that only the client can listen for. It fires approximately every frame. It is really useful for effects such as changing the transparency here.

1 Like

That worked, but there was a missing variable. I added it though.

It was just

local part = v before the transparency for loop.

oops, i just edited it with the fix

1 Like