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

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

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)

1 comment

0

code blocks pls

1 answer

✓ Accepted answer

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.

1 comment

0

thx, I'll try it out!

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