01 | Part.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 | UDim 2. 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 |
18 | end ) |
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?
You should use a boolean debounce.
01 | local HasbeenTouched = false -- Your debounce |
02 |
03 | Part.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 | UDim 2. new( 0.25 , 0 , 0.01 , 0 ), |
13 | "Out" , |
14 | "Sine" , |
15 | . 5 , |