New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

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

Asked by 11 days 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 205 — 11d

1 answer

Log in to vote
0
Answered by 11 days 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 — 11d
Ad

Answer this question