Having troubles with a script

Im planning on making an area title drop down whenever you touch an invisible noncollideable part.
The key result is for when i enter the part, the gui drops down once. and only once, and then when i leave the part then come back to it again, it appears, but for me its not working at all! I tried multiple functions but it just wont come to me.

-- Replace "Part" with the name of your non-collidable part
local nonCollideablePart = game.Workspace.AreaTitles["Crash Site"]

-- Replace "Gui" with the name of your GUI element
local gui = game.Players.LocalPlayer.PlayerGui.AreaTitles
local frame = gui.Frame

-- Replace "TweenInfo.new(1)" with your preferred tween duration and easing style
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)

-- Replace "areaName" with the name of the area you want to display
local areaName = "Crash Site"
local description = "A small island with a single eggdog and the wreckage of a space shuttle."

-- Create the tweens
local guiTweenShow = game:GetService("TweenService"):Create(frame, tweenInfo, {Position = UDim2.new(0, 0, 0, 0)})
local guiTweenHide = game:GetService("TweenService"):Create(frame, tweenInfo, {Position = UDim2.new(0, 0, -1, 0)})
local delayTime = 3 -- Replace with the number of seconds you want to delay before hiding the GUI

local debounce = false

-- Function to display the GUI and start the tween
local function showAreaName()
	if debounce == false and game.Players.LocalPlayer.Character and game.Players.LocalPlayer.Character:FindFirstChild("Humanoid") and nonCollideablePart:IsTouching(game.Players.LocalPlayer.Character.Humanoid) then
		debounce = true
		frame.Back.AreaTitle.Text = areaName
		frame.Back.Description.Text = description
		guiTweenShow:Play()
		wait(delayTime)
		guiTweenHide:Play()
		wait(1)
		debounce = false
	end
end

-- Connect the show function to the non-collidable part's touch event
nonCollideablePart.Touched:Connect(showAreaName)

image

So the issue is that it doesn’t work, not even once?
Did you test that all of those many conditions in your if statement are being met already? That’s probably the first thing you should do when a problem like this arises. Ask yourself “this section of code isn’t running, what would prevent it from running?” and work from there.

In particular though, this looks a little off to me.

Have you verified that IsTouching works on a Humanoid?

Yep saw that, but thats only part of the solution

-- Replace "Part" with the name of your non-collidable part
local nonCollideablePart = game.Workspace.AreaTitles["Crash Site"]

-- Replace "Gui" with the name of your GUI element
local gui = game.Players.LocalPlayer.PlayerGui.AreaTitles
local frame = gui.Frame

-- Replace "TweenInfo.new(1)" with your preferred tween duration and easing style
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)

-- Replace "areaName" with the name of the area you want to display
local areaName = "Crash Site"
local description = "A small island with a single eggdog and the wreckage of a space shuttle."

-- Create the tweens
local guiTweenShow = game:GetService("TweenService"):Create(frame, tweenInfo, {Position = UDim2.new(0, 0, 0, 0)})
local guiTweenHide = game:GetService("TweenService"):Create(frame, tweenInfo, {Position = UDim2.new(0, 0, -1, 0)})
local delayTime = 3 -- Replace with the number of seconds you want to delay before hiding the GUI

local debounce = false

-- Function to display the GUI and start the tween
local function showAreaName(hit)
	if debounce == false and game.Players.LocalPlayer.Character and game.Players.LocalPlayer.Character:FindFirstChild("Humanoid") and hit:FindFirstAncestorOfClass("Model") == game.Players.LocalPlayer.Character then
		debounce = true
		frame.Back.AreaTitle.Text = areaName
		frame.Back.Description.Text = description
		guiTweenShow:Play()
		wait(delayTime)
		guiTweenHide:Play()
		wait(1)
		debounce = false
	end
end

-- Connect the show function to the non-collidable part's touch event
nonCollideablePart.Touched:Connect(showAreaName)

but it shows it whenever i jump and whenever i leave the area it shows it

This is the crash site areatitle load zone, whenever i leave it, it shows the gui because right when i leave it theres a frame where it touches it at the same time, i want it so the gui shows once, doesn’t show when i jump or move around the place, and doesn’t show when i leave it, but when i get inside again, it shows it

Maybe turn off CanTouch after your gui appears or you could use Region3 to detect the player and if player is in the area display your gui one time.

Here’s an simple example, using Region3:

local RunService = game:GetService("RunService")
local Players = game:GetService("Players")

local player = Players.LocalPlayer
local character = player.Character
local HumanoidRootPart = character:WaitForChild("HumanoidRootPart")

local zone = workspace.Zone
local inZone = false
local AlreadyDisplayed = false

RunService.RenderStepped:Connect(function()
	if player.Character ~= nil then
		local region3 = Region3.new(zone.Position - (zone.Size/2), zone.Position + (zone.Size/2))
		local PartsInRegion = workspace:FindPartsInRegion3WithWhiteList(region3, {HumanoidRootPart})	

		inZone = #PartsInRegion > 0

		if inZone and not AlreadyDisplayed then
			print("display gui!")
			AlreadyDisplayed = true

		elseif not inZone and AlreadyDisplayed then
			print("can display gui again!")
			AlreadyDisplayed = false
		end
	end
end)

Replace wait(1) inside of the showAreaName function with this line

repeat wait(1) until not table.find(nonCollideablePart:GetTouchingParts(), hit)

This is a loop, but it should be fine. It’s not doing a tremendous amount of work, and the TouchEnded event is extremely unreliable or I’d use it instead.

1 Like

Yo! It worked tysm!!!
That probably fixed it

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.