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

Cool down for Touched Event?

Asked by 5 years ago
01Part.Touched:Connect(function(hit)
02    local Hit = hit.Parent:FindFirstChild("Humanoid")
03    if Hit then
04        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
05        if player then
06            if player.OtherInfo.Backpack.Value < player.OtherInfo.MaxBackpack.Value then
07                Gui:TweenPosition(
08                    UDim2.new(0.25, 0,0.01, 0),
09                    "Out",
10                    "Sine",
11                    .5,
12                    false
13                )
14                wait(5)
15            end
16        end
17    end
18end)

I have tried this but it doesn't work. What I want to do is when the player touches a part it drops down a gui but when they close and go of the part then it opens again because it detects the player touching it. Does anyone know how to fix this?

1 answer

Log in to vote
1
Answered by
SnowieDev 171
5 years ago

You should use a boolean debounce.

01local HasbeenTouched = false -- Your debounce
02 
03Part.Touched:Connect(function(hit)
04    local Hit = hit.Parent:FindFirstChild("Humanoid")
05    if Hit then
06        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
07        if player then
08            if player.OtherInfo.Backpack.Value < player.OtherInfo.MaxBackpack.Value then
09                if HasbeenTouched == false then
10                    HasbeenTouched = true
11                    Gui:TweenPosition(
12                    UDim2.new(0.25, 0,0.01, 0),
13                    "Out",
14                    "Sine",
15                    .5,
View all 24 lines...
Ad

Answer this question