Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Is there a way to prevent delayed .Touched event?

I'm having problems with the .Touched event, when i touch the part its delayed by 1 second or more, this is a single player so if there is a way so that if one client jumps on a brick only the client will see and can jump on the brick but not other clients i would use it. Here is the script i used.

Local function OnTouch ()
	script.Parent.Transparency = 0.5
	script.Parent.Parent.Part1.Transparency = 0.5
	script.Parent.Parent.Part1.CanCollide = true
	wait(0.2)
	script.Parent.Transparency = 1
	script.Parent.CanCollide = false
	script.Parent.parent.Part1.Transparency = 0
	wait(5)
	script.Parent.Transparency = 0
	script.Parent.CanCollide = true
	script.Parent.Parent.Transparency = 1
	script.Parent.Parent.CanCollide = false
end


script.parent.touched.connect (OnTouch)

1 comment

0

Put it in a localscript to make it so that it only affects the individual client, but I don't think there is a way to prevent the delay.

1 answer

✓ Accepted answer

You have capitalized local and are also using depreciated items.

-- Declaration Section 
local Workspace = game:GetService("Workspace")

-- //Part
local Part1 = Workspace:WaitForChild("Part1")
local Part2 = Workspace:WaitForChild("Part2")

-- Processing Section 

local function ChangePartProperties (hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		Part1.Transparency = 0.5
		Part2.Transparency = 0.5
		Part2.CanCollide = false 
		
		wait(0.2)
		
		Part1.Transparency = 1
		Part2.Transparency = 1
		Part2.CanCollide = true 
		
		wait(0.2)
		
		Part1.Transparency = 0
		Part2.Transparency = 0
		Part2.CanCollide = false 
	end
end

-- Connecting Section 
Part1.Touched:Connect(ChangePartProperties)

**Avoid using connect as it is depreciated. Use Connect.**

**It is not Local but rather local.**

I personally despise script.Parent so I changed it up.

But you should immediately see some changes after these small fixes.

#####Have a lovely day of coding.

1 comment

0

thanks it worked fine.

This discussion is preserved as it was. New answers, comments, and votes are closed.