Location Name Pop up not working again (still looking for a fix)

What do i want to achieve?

i want to make this working.

What is the issue?

when i re-enter a location it doesn’t play the animation again. i don’t know if even the text changes. here is the code (local script):

local locations = game.Workspace.Locations
local label = script.Parent.Title
local location = nil

while wait(1) do
	for i, v in pairs(locations:GetChildren()) do
		local min = Vector3.new(v.Position.X - (v.Size.X / 2), v.Position.Y - 100, v.Position.Z - (v.Size.Z / 2))
		local max = Vector3.new(v.Position.X + (v.Size.X / 2), v.Position.Y + 100, v.Position.Z + (v.Size.Z / 2))
		local region = Region3.new(min, max)
		
		for _, player in pairs(game.Workspace:FindPartsInRegion3(region, nil, math.huge)) do
			if player.Parent:FindFirstChild("Humanoid") then
				if location ~= v.Name then
					location = v.Name
					label.Text = location
					label.TextColor3 = v.Color
					
					label:TweenPosition(UDim2.new(0, 0, 0, 0), 'Out', 'Sine', '1')
					wait(3)
					label:TweenPosition(UDim2.new(0, 0, 1, 0), 'Out', 'Sine', '1')
				elseif location == v.Name then
					
				end
			end
		end
	end
end

Edit: you can change the script to that there is a huge block and when you are inside that block then you’re in that location.

2 Likes

Try this

local locations = workspace.Locations
local label: = script.Parent.Title
local location = nil

while task.wait(1) do
	for i, v in pairs(locations:GetChildren()) do
		local Size = Vector3.new(v.Size.X, 200, v.Size.Z)
		for _, player in pairs(workspace:GetPartBoundsInBox(v.CFrame, Size)) do
			if player.Parent:FindFirstChild("Humanoid") then
				if location ~= v.Name then
					location = v.Name
					label.Text = location
					label.TextColor3 = v.Color

					label:TweenPosition(UDim2.new(0, 0, 0, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 1)
					task.wait(3)
					label:TweenPosition(UDim2.new(0, 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 1)
				elseif location == v.Name then

				end
			end
		end
	end
end

The fourth value of TweenPosition must be a number and FindPartsInRegion3 and wait are deprecated.


Sources: GetPartBoundsInBox - task library

2 Likes

now it does play. but the text is bugged like when i move to a diffirent location then the text changes with an animation but when i walk around then it bugs out and plays another time with the location name changing.

1 Like

Here is the problem i have (sorry for the bad quality):

1 Like

I believe that’s because of the existing task.wait in your code. My guess is that the issue is caused by the following:

  • Entering the Lobby sets the label text, then it tweens upwards
  • task.wait(3) is executed, and yields before moving to the next instruction.
  • Before task.wait() is finished executing, you enter the Testing Area in less than 3 seconds.
  • task.wait(3) from the thread where you enter the Lobby stops yielding and calls the tween downwards animation. It overwrites the animation where the label tweens upwards.

You can probably check if the location has changed when task.wait is finished.

task.wait(3)
-- tween downwards if the location hasn't changed
if location==v.Name then 
label:TweenPosition(UDim2.new(0, 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 1)
end

@vfIour nothing changes. here’s the script (if i put in the wrong place):

local locations = workspace.Locations
local label = script.Parent.Title
local location = nil

while task.wait(1) do
	for i, v in pairs(locations:GetChildren()) do
		local Size = Vector3.new(v.Size.X, 200, v.Size.Z)
		for _, player in pairs(workspace:GetPartBoundsInBox(v.CFrame, Size)) do
			if player.Parent:FindFirstChild("Humanoid") then
				if location ~= v.Name then
					location = v.Name
					label.Text = location
					label.TextColor3 = v.Color

					label:TweenPosition(UDim2.new(0, 0, 0, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 1)
					task.wait(3)
					-- tween downwards if the location hasn't changed
					if location==v.Name then 
						label:TweenPosition(UDim2.new(0, 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 1)
					end
				elseif location == v.Name then

				end
			end
		end
	end
end

So I tested your script. Apparently it’s because of the way tweens interrupt eachother. There’s also an additional parameter with tweens where you can determine whether or not they interrupt eachother. I also suggest resetting the position before tweening, because it’ll only show the text/color change.

label.Position = UDim2.new(0, 0, 1, 0)
label:TweenPosition(UDim2.new(0, 0, 0, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 1,true)

task.wait(3)

label:TweenPosition(UDim2.new(0, 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 1,false)

I also noticed a strange issue where the timing will be a little delayed for when you call the method. That’s because you’re using task.wait(1) during the while loop, which is causing that delay. You can probably use an event like RunService.RenderStepped or RunService.Heartbeat. I haven’t tested it though, lol.

1 Like

@vfIour @vfIour the issue is still here. here is how it looks now (it loops):

code:

local locations = workspace.Locations
local label = script.Parent.Title
local location = nil
while task.wait(1) do

for i, v in pairs(locations:GetChildren()) do

local Size = Vector3.new(v.Size.X, 200, v.Size.Z)

for _, player in pairs(workspace:GetPartBoundsInBox(v.CFrame, Size)) do

if player.Parent:FindFirstChild("Humanoid") then

if location ~= v.Name then

location = v.Name

label.Text = location

label.TextColor3 = v.Color

label.Position = UDim2.new(0, 0, 1, 0)

label:TweenPosition(UDim2.new(0, 0, 0, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 1,true)

task.wait(3)

label:TweenPosition(UDim2.new(0, 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 1,false)

elseif location == v.Name then

end

end

end

end

end

also idk why does the code look like this since it’s normal in studio but yea

i hope that someone will help me

1 Like

I apologize for the late response. I think it’s because of the task.wait(3) in between the two tweens, causing it to yield before it can check the bounding box of the next part. I replaced it with this, so that it doesn’t have to yield:

label:TweenPosition(UDim2.new(0, 0, 0, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 1,true)
task.delay(3,function()
	label:TweenPosition(UDim2.new(0, 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 1,false)
end)

You should probably remove the elseif location==v.Name then as it won’t do anything. It just makes the code a little more annoying to read. (unless, of course, you’re planning to add something in there! I can’t really assume much with what you want to do.)
Also, changing the while wait(1) do with an event connection, ie:

game:GetService("RunService").RenderStepped:Connect(function()
-- insert body here 
end)

Will make it seem more responsive. There’s a bit of an awkward wait time when you switch locations.

@vfIour Well i updated it. But now when i switch to the “Testing Area” Location then it just doesn’t play again! Only the “Lobby” Works. (and the animation became faster when i re-entered the “Lobby” Area)

Here is the code:

local locations = workspace.Locations
local label = script.Parent.Title
local location = nil

game:GetService("RunService").RenderStepped:Connect(function()
	for i, v in pairs(locations:GetChildren()) do
		local Size = Vector3.new(v.Size.X, 200, v.Size.Z)
		for _, player in pairs(workspace:GetPartBoundsInBox(v.CFrame, Size)) do
			if player.Parent:FindFirstChild("Humanoid") then
				if location ~= v.Name then
					location = v.Name
					label.Text = location
					label.TextColor3 = v.Color

					label.Position = UDim2.new(0, 0, 1, 0)
					label:TweenPosition(UDim2.new(0, 0, 0, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 1,true)
					task.delay(3,function()
						label:TweenPosition(UDim2.new(0, 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 1,false)
					end)
				end
			end
		end
	end
end)
1 Like