Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is there a way to prevent delayed .Touched event?

Asked by
CjayPlyz 643 Moderation Voter
6 years ago
Edited 6 years ago

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)
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. Faazo 84 — 6y

1 answer

Log in to vote
1
Answered by
Zafirua 1348 Badge of Merit Moderation Voter
6 years ago
Edited 6 years ago

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.
0
thanks it worked fine. CjayPlyz 643 — 6y
Ad

Answer this question