I am making a Shop Gui that opens when a player touched the specified part. I want this Gui to dissapear when the player walks off this part. I tried to make this happen with my own code but it does not work. I know why it happens but I do not know how to fix it. I prefer not having an closing icon for the Gui. Can someone help please?
#How do I not make the Shop Gui flicker?
1 messages · Page 1 of 1 (latest)
local shopGui = script.Parent
local shopGuiTrigger = game.Workspace.ShopGuiTrigger
shopGuiTrigger.Touched:Connect(function(hit)
local hum = hit.Parent:FindFirstChild("Humanoid")
local localPlayer = game.Players.LocalPlayer
if hum and localPlayer then
shopGui.Enabled = true
end
end)
shopGuiTrigger.TouchEnded:Connect(function(hit)
local hum = hit.Parent:FindFirstChild("Humanoid")
local localPlayer = game.Players.LocalPlayer
if hum and localPlayer then
shopGui.Enabled = false
end
end)
why do you think it happens
I guess every time I walk inside the part, the game counts thats as a touchEnded event.
not quite
your character is made up of parts and those parts can enter and leave the area quickly due to animations depending on its size and at the boundaries. your code does not distinguish this and so when any part belonging to the player enters or exits it will flash the gui, which can be several times per second.
i feel very stupid after reading this