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)
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.