Can Someone fix my script?

my script is

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)

You should tell us what are your problems and what do you want the script to do

I want it so If I’m on the white team and I touch a part my text label starts to start to start saying stuff like “what happened” etc “hello”

Try using this function:

function typeWrite(TextBox, Text)
    print(TextBox.Text)
    for i = 1,#Text do
        TextBox.Text = string.sub(Text, 1, i)
        wait(0.05)
    end
end

Example:

typeWrite(game.StarterGui.InfectMessageGUI.TextLabel, "Hello World!")

I tried that just now, didnt work?

Also, I’m trying to do something else. What you are telling me doesn’t help me at all. please reread my topic or this Can Someone fix my script? - #3 by Oozymage

Is it a local script or a normal script and do you want it to show for everyone or only to the player?

it’s a normal script, I wan’t it so if you are on the white team and you touch a part then it shows for the person who touched it.

Don’t do game.StarterGui, you should do plr.PlayerGui!

still didn’t work. I tried that.

Can you show me the output, please?

Nothing in the output, like I said I want the message to appear when u touch a part.

Oh… got it! You can’t enable the script from the same script when it’s disabled.

Instead of using player added you can get the player from it’s character by doing

local plr = game.Players:GetPlayerFromCharacter(Hit.Parent)

You have several issues here.

  1. Server scripts do not run from the PlayerGUI, move the script to ServerScriptService.

  2. Do not add the hit detection in player added. Only do it once on the outter scope and check the player associated with hit:

for _, Part in pairs(InfectionParts:GetChildren()) do
	Part.Touched:Connect(function(Hit)
	local plr = game.Players:GetPlayerFromCharacter(Hit.Parent)
    ...
end
  1. You are missing an elseif in there… the way you have the logic with the nested if, it says the player has to be both red and white team at the same time… so this:
if plr.TeamColor == BrickColor.new("Really red") then
   print("red!")
elseif plr.TeamColor == BrickColor.new("White") then
   print("white!")
end
  1. Don’t forget you probably want to change the player’s team color from white to red.

  2. Lastly, you can’t change the game.StarterGui.InfectMessageGUI.TextLabel you must change the player’s specific GUI. This will require a local script to manipulate. You will want to add a RemoteEvent to fire from the server script that triggers your typing in the local script.

2 Likes