Im trying to make a simple sell/shop area where the player steps into a circle, and then the circle opens the gui for them to sell/buy something.
The problem is, Is when they walk around in the circle it obviously triggers the .Touched event multiple times, so I made a bigger part that covers the shop area and added a .TouchEnded event. But for some reason the touch ended event triggers even when the player is completely inside of the part. Please let me know if theres a better way to make a shop circle, or if there a way to rectify this code. Thank you!
local part = script.Parent
local check = script.Parent.Parent.Outer
local togglegui = game.ReplicatedStorage.ToggleSellGui
local able = true
-- Calls when the player steps on the circle to open the gui
part.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player and able then
local leaderstats = player:WaitForChild("leaderstats")
-- this opens the gui and then stops the player from opening it again
togglegui:FireClient(player, true)
able = false
print("UNABLE TO")
end
end
end)
-- this is supposed to call when the player leaves a part that covers the shop area
check.TouchEnded:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
able = true
print("ABLE TO")
end
end
end)