Hep needed! (Scripting, Part + TextLabels)

I want it so if your on white team and u touch a part then a text label appears, but it isnt working? (make it show for the person who touched)

local WS = game:GetService("Workspace")
local PS = game:GetService("Players")
local InfectionParts = WS:WaitForChild("Infectors", 5)

game.Players.PlayerAdded:Connect(function(plr)
	for _, Part in pairs(InfectionParts:GetChildren()) do
		Part.Touched:Connect(function(Hit)
			if plr.TeamColor == BrickColor.new("Really red") then
				script.Disabled = true
				if plr.TeamColor == BrickColor.new("White") then
					script.Disabled = false
					game.StarterGui.InfectMessageGUI.TextLabel.Text = "Wh"
					wait(1)
					game.StarterGui.InfectMessageGUI.TextLabel.Text = "Wh-"
					wait(1)
					game.StarterGui.InfectMessageGUI.TextLabel.Text = "Wha"
					wait(1)
					game.StarterGui.InfectMessageGUI.TextLabel.Text = "What"
					wait(1)
					game.StarterGui.InfectMessageGUI.TextLabel.Text = "What ha"
					wait(1)
					game.StarterGui.InfectMessageGUI.TextLabel.Text = "What hap"
					wait(1)
					game.StarterGui.InfectMessageGUI.TextLabel.Text = "What happ"
					wait(1)
					game.StarterGui.InfectMessageGUI.TextLabel.Text = "What happen"
					wait(1)
					game.StarterGui.InfectMessageGUI.TextLabel.Text = "What happened"
					wait(1)
					game.StarterGui.InfectMessageGUI.TextLabel.Text = "What happened..?"
				end
			end
		end)	
	end		
end)

It’s a normal script, it’s inside a text label. Text Label inside of screengui)

Right here, you should be using plr.PlayerGui.InfectMessageGUI because StarterGui is replicated to the player when the player joins or respawns.

1 Like

Alright thanks, I just did that. but now what?

There are alot of problems I see that you’re making here:

  1. Normal script in text label, where they won’t even run.
  2. Using Player Added in it is useless, where you can just use a localscript and get localplayer.
  3. I don’t get why you’re disabling the Script?
  4. You also should check if the Hit is actually a player character.
  5. You can use a loop instead of so many statements
  6. Even if you did do it from a server sided script, its not recommend to change UI from server side.
  7. You also referenced StarterGui instead of PlayerGui (As said earlier in the thread), they are different things.
1 Like

This part is weird. Shouldn’t this check if it is red then return or something and use elseif for the checking of white? Also, if the script disables itself, how is it supposed to reenable itself?

okay… thanks for stating that. but I’m not a kind of person that understands that really good.

what I did there was I tried doing if you are on the Really red team then if you touch a block the message wont appear, but if you are on the white team and u touch the block the message appears.

You create an if then elseif then end statement. You first check if the player is on the really red team and then if they are, I think what you are going for here is to not do anything, so in that if statement, don’t put anything there. Then after the elseif is where you would put the part where you check if the player is on white, and if they are, then do the stuff.

God, I already told you! you can’t disable the script then set it to false in the same script again.

Hey there!

So I may be wrong, but it’s not displaying for perhaps a few reasons. First of all, you are changing
the .Text of an item in StarterGUI, but the issue with this is that StarterGui is only the place where it holds the guis before they are replicated. You need to do

plr.PlayerGui.InfectMessageGUI.TextLabel.Text = "Wh"

instead since that’s where the player’s real guis are. You are editing a text value for a GUI in
StarterGui, but that’s only where the guis are stored before being replicated on the player’s PlayerGui. Basically, you’re editing a stored gui instead of the active one being used by the player.

Also, this method of setting the text is pretty in-efficient, and might be confusing to edit later on.
I suggest using a method like this for typewriter effects.

local displayText = "What happened...?"
local currentText = ""

for index = 0, string.len(displayText) do
    currentText = string.sub(displayText, 1, index)

    plr.PlayerGui.InfectMessageGUI.TextLabel.Text = currentText
    wait(0.15)
end

This should do the job quick and efficiently! Forgive me if it formats oddly though, since I wrote
this directly on the post and not in studio.

Hope this helps! :smiley: