How to make the GUI appear once when being on the zone and disappear once when exiting the zone?

Can anyone tell me what’s the problem? I’m trying to make when I enter the zone, a textlabel comes to the screen and hops off when I exit the zone.
I managed to make it appear when being in the zone but I couldn’t figure out how to make it disappear when exiting the zone, I’ve tried TouchEnded but it thinks that I’m no longer in the zone so it disappears directly after I stay on the zone.
NOTE: The zone is a union

local debounce = true
local brick = game.Workspace.Safezonemodel.Union
brick.Touched:Connect(function(hit)
	if hit and hit.Parent:FindFirstChild("Humanoid") and debounce == true then
		local object = script.Parent
		object.Position = UDim2.new(0.184, 0, 1, 0)

		object:TweenPosition(UDim2.new(0.184, 0,0.8, 0))	
		debounce = false
		if hit.Parent:FindFirstChild("Humanoid") == nil and debounce == false then
			local object = script.Parent
			object.Position = UDim2.new(0.184, 0, 0.8, 0)

			object:TweenPosition(UDim2.new(0.184, 0, 1, 0))	
			debounce = true
		end
	end
end)

I’ve tried ZonePlus but when I walk randomly on the zone, it randomly executes the zone.playerexited, and then the zone. zone.playerentered come back. But all I did was I stayed in the zone

local Zone = require(game:GetService("ReplicatedStorage").Zone)
local container = workspace.Safezonemodel.Union
local zone = Zone.new(container)

zone.playerEntered:Connect(function(player)
    local object = script.Parent
    object.Position = UDim2.new(0.184, 0, 1, 0)

    object:TweenPosition(UDim2.new(0.184, 0,0.8, 0))    
end)

zone.playerExited:Connect(function(player)
    local object = script.Parent
    object.Position = UDim2.new(0.184, 0, 0.8, 0)

    object:TweenPosition(UDim2.new(0.184, 0, 1, 0))
end)

I really do not understand what’s going on, if there’s anyone to help me, I would be grateful!

2 Likes

Why don’t you try using region3?

Sorry, what do you mean by that?

The zone has a specific shape, it would be hard to use region3 in that kind of situation.


Local part = -- the part
If part.touched:connect(function()
Local gui = --the gui
Gui.visible = true

 Else

 Gui.visible = false
End)

Maybe try this if the code is bad im sorry im kind an amateur. Think I forgot an end on there but dont have my computer cant check.

This won’t even work at all, First of all it should be

local

Not

Local

Second of all it should be “if” not “If”
Third of all if doesn’t work with functions?

You should remove if.

4th of all it should be “end” not “End”.

5th of all you can’t use “else” in functions.

1 Like

I know about the capitulation errors im on my phone auto corrects

What I mean by appearing is like a tween. I managed to do that, no problem, but if I do part.touched without any debounce or anything, it’ll make a repeat tween service which is absolutely what I do not want to do!

Have you tried using TouchEnded?

I’ve tried TouchEnded but it thinks that I’m no longer in the zone so it disappears directly after I stay in the zone.

I’ve said it on the topic, but I’m gonna say it back again. What I want to do is make my tween GUI appear once on the screen and disappear once off the screen. but for this, I have to do debounce, a variable that will make me able to show the GUI only once. Go look at the first script.
I’ve tried zoneplus but it didn’t work.

TouchEnded is incredibly unreliable.

1 Like

I’ll give you the most simple answer I can think of which is having a very thin sphere around the zone and putting something like this:

local ZONESPHERE = "the sphere"

local ENTERED = false

ZONESPHERE.Touched:Connect(function(hit)
	if not hit.Parent:FindFirstChild("HumanoidRootPart") then return end
	if ENTERED == true then
		ENTERED = false
		-- they are currently in the zone
	elseif ENTERED == false then
		ENTERED = true
		-- they are currently outside the zone
	end
end)

I made this in like 15 seconds and haven’t tested it please don’t bully me :sob:

Quick question…
Is this on the server or client?

If you are just updating the local player’s UI using the zone I would use the zone.localPlayerEntered and zone.localPlayerExited events. All effects and UI changes should be done on the client anyway to reduce strain on the server.

As for why the events are firing multiple times, it might be due to your zone moving or changing size. There are properties you can change in ZonePlus to remove this updating event if that’s the case.

Just want to tell you that it doesn’t work, it keeps repeating when I walk.

This is a client script, it only shows the text to the player that is in the zone.

I made the changes of putting localPlayerEntered event but still no changes. The zone is not moving or changing size but can you tell me where can I remove the updating event? Maybe it’ll change something?

If the parts aren’t moving or changing size I doubt that’s the issue, however, if you want to try it I believe it’s something like zone.autoUpdate = false. Maybe it’s an issue with your union’s collision fidelity? Have you tried adding a print statement into each event to confirm that the events are firing when they are supposed to?

I’ve tried zone.autoUpdate = false, it didn’t work, I’ve tried to print in each event and it prints randomly when I walk on the zone. So the problem might be the union’s collision, just to let you know, the union is hexagon shaped.

1 Like

I managed to fix it, as I thought, the problem was the union collision, to confirm this I did put the collision to box and it worked fine. I’ve set up mine at “Hull” and it works perfectly (With zone plus)!

1 Like