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

dw abt it! I have been having a lot of problems with the code I was doing so it was good to take a break from it! The fading is looking really weird for me, not sure why, but other than that i have it all working. I will edit my other post to include the working code (and what I did) when I am done.

1 Like

Ok made it work! Here is the code:

local Players = game:GetService("Players")

touch = game.Workspace:WaitForChild("touch") --change this to find your part

touch.Touched:Connect(function(hit)
	
	local character = hit.Parent
	
	if character then
		player = Players:GetPlayerFromCharacter(character)
	else
		warn("character not found")
	end
	
	if player then
		wait(0.5)
		touch:Destroy()
		
		local ui = player.PlayerGui
		
		ui.MapTitle.TextLabel.Text = "Map_Test1"
		ui.MapTitle.TextLabel.TextTransparency = 1
		
		while ui.MapTitle.TextLabel.TextTransparency > 0 do
			wait(0.1)
			ui.MapTitle.TextLabel.TextTransparency = ui.MapTitle.TextLabel.TextTransparency - 0.1
		end
		
		wait(1)
		
		while ui.MapTitle.TextLabel.TextTransparency < 1 do
			wait(0.1)
			ui.MapTitle.TextLabel.TextTransparency = ui.MapTitle.TextLabel.TextTransparency + 0.1
		end
	else
		warn("player not found")
	end
end)

I changed the repeat until loops to while loops and I changed the place where it is looking for the gui from starter gui to that players gui. As far as I can see, your repeat until loops should have worked fine, but for whatever reason they were being weird so I changed them out for while loops, which I am more familiar with. Good luck with your game!

If this worked then please mark it as solution! :slight_smile:

2 Likes


Uhhm…this happened

Also thanks for the goodluck. :smiley:

Uh… Is anything else touching the part?

EDIT: Is this in a local script?

1 Like

Ohh it needs to be in a server script in server script service

1 Like

The part is touching the floor and wall and yes it is. It’s located in StarterCharacterScripts

hmm ok, does it work for you to have it as a server script or does it need to be local? I can edit it so it works with local if you want

1 Like

That may be the problem.

No thats just getting mad at me because I didnt put local in front of it. Its more of a suggestion, the code works with it as global. If I were to put it as local player = ... instead of player = ... it would break the code. Its a weird studio glich.

1 Like

Oh!,Okay! :smiley:

this kind of scared me, i thought i was being mean I’m so sorry.

So, do I leave it as it is?

P.S it’s not working now…:frowning:

It did fade out last time after my second try I forgot to mention that.

Oh sorry no, I meant studio is getting mad at me, I have had it telling me that “error” all day :grinning_face_with_smiling_eyes:

put this in a local script in starter player scripts:

local Players = game:GetService("Players")

touch = game.Workspace:WaitForChild("touch")

touch.Touched:Connect(function(hit)

	local player = Players.LocalPlayer

	if player then
		touch:Destroy()

		local ui = player.PlayerGui

		ui.MapTitle.TextLabel.Text = "Map_Test1"
		ui.MapTitle.TextLabel.TextTransparency = 1

		while ui.MapTitle.TextLabel.TextTransparency > 0 do
			wait(0.1)
			ui.MapTitle.TextLabel.TextTransparency = ui.MapTitle.TextLabel.TextTransparency - 0.1
		end

		wait(1)

		while ui.MapTitle.TextLabel.TextTransparency < 1 do
			wait(0.1)
			ui.MapTitle.TextLabel.TextTransparency = ui.MapTitle.TextLabel.TextTransparency + 0.1
		end
	else
		warn("player not found")
	end
end)

I had it coded for a server script but now I realize that wont work because the part would disappear for everyone so after the first person joined nobody else would get the message. The code above should work tho.

2 Likes

Nothing happened… again… :frowning: it just doesn’t do anything. Not even an output.

ugh oh boy k lemme test it. It works for me but I will try some stuff.

1 Like

You seem like you’re having a tough time. Are you sure you want to continue to help me? :sweat_smile:

No its fine, this is better than working on what I was doing before! :slight_smile: I am still testing stuff, it worked in solo play, idk what it is doing when i simulate 3 clients in studio, and I am trying to publish my test as a real game so I can try it in roblox but it wont show up. I will get back to you wen I can get something working

1 Like

Thsi is what i have to test it, I moved the part that you touch to see the change sideways so that you can see when the change happens. It is working here so it might be other parts of your game that arent working with the existing script.

Test game cause idk why roblox doesnt work - Roblox

1 Like

I know this may not be the issue but could it be because the object is non-collidable? CanTouch is still enabled but I didn’t make it collidable so people won’t know that they are triggering this by touching or going through the part. (It’s transparent)

No, I dont think that is the issue. Did it work in my test game for this for you, I found it working for me?

1 Like

Yes, it worked just fine without any issues.

hmm ok. Can I see your explorer window for the part that you touch? and for the script?

1 Like