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

Hi, wondering how to make it so that it only detects a hit once?

Asked by 3 years ago

When a player touches the part this script is assigned to, the shop GUI flashes on the screen because the parts that hit the part all have Humanoid in their parent. How do I make it so that it only does it once, and when the player leaves the shop circle, the GUI closes?

Shop = game.Workspace.ShopModel:FindFirstChild("Shop")

Players = game:GetService("Players") player = Players.LocalPlayer

Shop.Touch.Touched:Connect(function(hit) hit = hit.Parent:FindFirstChild("Humanoid") if hit ~= nil then local ShopGUI = player:FindFirstChild("ShopGUI",true) ShopGUI.Enabled = true
end end)

Shop.Touch.TouchEnded:Connect(function(hit) hit = hit.Parent:FindFirstChild("Humanoid") if hit ~= nil then local ShopGUI = player:FindFirstChild("ShopGUI", true) ShopGUI.Enabled = false end end)

0
code blocks pls matiss112233 258 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

Touched and TouchEnded tend not to work properly with characters due to animations.

You are better off doing a region3 check to verify the players remain in the area or use GetTouchingParts() to check if the feet of the player are still touching the part.

0
thx, I'll try it out! NoteSalad 17 — 3y
Ad

Answer this question