I need help; when a person touches an object, a screen UI text fades in and out

Hello developers,

I am trying to make a script so when a person spawns in a map, they will hit a non-collidable but touchable part (as they spawn) and activate a UI text saying the map’s name at the bottom.

Problem is, when I try to do this, it just straight up does not work. No errors in the output.

This may be a very dumb mistake because I’m not good at scripting.

Here’s the code

local ui = game:GetService("StarterGui")

touch.Touched:Connect(function()

	ui.MapTitle.TextLabel.Text = "Map_Test1"
	repeat
		wait()
		ui.MapTitle.TextLabel.TextTransparency = ui.MapTitle.TextLabel.TextTransparency - 0.01	
	until
	ui.MapTitle.TextLabel.TextTransparency == 0
	wait(1)

	repeat
		wait()
		ui.MapTitle.TextLabel.TextTransparency = ui.MapTitle.TextLabel.TextTransparency + 0.01	
	until
	ui.MapTitle.TextLabel.TextTransparency == 1


end)

wait(0.01)
touch:Destroy()

Any help please? I’d appreciate some help! :slight_smile:

And please, remember I suck at coding. So, don’t be shocked if it’s a dumb mistake.

Akridiki

4 Likes

You are firing the same code over and over everytime the part is touched, with the result being it never starting, without errors.

I would suggest deleting the part right after Touched is fired, so it runs once only.
It should work if the script isn’t a child of the “touch” part, iirc.

1 Like

Also try setting off the ui change manually in your script, without waiting for the touched event, because that way you know if it is the script or the touching that doesn’t work. You could add a debounce too, with the same effect as what someone said above me

EDIT: Is the touching the part required? because if you just want to play the text when they join, you can do this:

Players = game:getService("Players")
Players.PlayerAdded:Connect(function()
    --your code, without the part touching event
end)

Another note, I think we are supposed to use task.wait() instead of wait() but I am not 100% sure.

1 Like

Nope, since they will teleport to many maps then no, this won’t really solve it. but, I’ll try the other part! :slight_smile:

1 Like

Are the maps in different places, or the same one? If they are different places, I think .PlayerAdded will work

I really don’t understand this part… because, again. I’m a rookie in scripting so that’s a little complex for me. :sweat_smile:

1 Like

They are in the same place. (30char)

1 Like

Just change the code to run after like 5 seconds or something, taking out the touch.Touched:Connect(function() part of it

1 Like

ok, then player added wont work ig

1 Like

But how will this work if people have to move on to other maps after they finish a map?

1 Like

it would just be a test, to see if it is the touching that is broken or the scripting that is broken

1 Like

it didn’t work…? o_o 30303030303030

:expressionless:
ok let me try some stuff in studio. Can i see the modified testing script? still no errors?

1 Like

Wait a minute, I just realized.
Are you changing the UI of StarterGui? Shouldn’t it be PlayerGui?

1 Like
local ui = game:GetService("StarterGui")

wait(5)
	touch:Destroy()
	ui.MapTitle.TextLabel.Text = "Map_Test1"
	repeat
		wait()
		ui.MapTitle.TextLabel.TextTransparency = ui.MapTitle.TextLabel.TextTransparency - 0.01	
	until
	ui.MapTitle.TextLabel.TextTransparency == 0
	wait(1)

	repeat
		wait()
		ui.MapTitle.TextLabel.TextTransparency = ui.MapTitle.TextLabel.TextTransparency + 0.01	
	until
	ui.MapTitle.TextLabel.TextTransparency == 1


wait(0.01)

have you declared the touch variable anywhere? like touch = game.Workspace:WaitForChild("touch") or whatever?

1 Like

Nevermind, I did script.TextTouch because the part was in the script.

Ok

I think I might know the problem. I think you need to be coding the gui on the client? Or at least referencing the gui as the client. Right now I think you are just changing it in starter gui which wont make a difference for people in the game. Is your script in serverscriptserice?

EDIT: I just realized, @WorkPro2007 said what i said above further up, I didnt even notice! You will need to be coding it so that you are changing it in playergui, the client where the gui is, not starter gui. Starter gui gets replicated to any new players who join, but the players see the gui in playergui

2 Likes

I think I made it work! Try this:

local Players = game:GetService("Players")

part = game.Workspace:WaitForChild("touch") -- change this to whatever/wherever your part is

part.Touched:Connect(function(hit)
	
	local character = hit.Parent
	
	if character then
		player = Players:GetPlayerFromCharacter(character)
	else
		warn("character not found")
	end
	
	if player then
		part:Destroy()
		
		local ui = player.PlayerGui
		
		ui.MapTitle.TextLabel.Text = "Map_Test1"
		ui.MapTitle.TextLabel.TextTransparency = 1
		repeat
                        wait()
			ui.MapTitle.TextLabel.TextTransparency = ui.MapTitle.TextLabel.TextTransparency - 0.01	
		until
		ui.MapTitle.TextLabel.TextTransparency == 0
		wait(1)

		repeat
			wait()
			ui.MapTitle.TextLabel.TextTransparency = ui.MapTitle.TextLabel.TextTransparency + 0.01	
		until
		ui.MapTitle.TextLabel.TextTransparency == 0


		wait(0.01)
	else
		warn("player not found")
	end
end)

Ok, it half works. For some reason it is fading in (very slowly) but not fading out before that. So let me try to fix it and i will edit the code above as I do.

1 Like

Thanks so much! Mind telling me how you fixed it once you’re done? Also, thanks for taking ur time! :smiley:

1 Like