Why Is My Gui Text Script Not working?

  1. What do I want to achieve? I want to make my text visible and say things when a part is touched

  2. What is the issue? The script is not working and it says this in the output image

  3. What solutions have you tried so far? I’ve tried looking on the Dev Forum!

This is my script!

local First = game.Workspace.First
local Second = game.Workspace.Second
local Third = game.Workspace.Third
local Fourth = game.Workspace.Fourth



First.Touched:Connect(function(plr)
	local plrGui = plr.PlayerGui
	plrGui.Texted.TextLabel.Visible = true
	plrGui.Text.TextLabel = "???:Wait What Why Am I Here?"
	wait(5)
	plrGui.Texted.TextLabel.Visible = false
end)


Second.Touched:Connect(function(plr)
	local plrGui = plr.PlayerGui
	plrGui.Texted.TextLabel.Visible = true
	plrGui.Text.TextLabel = "???:Why did people turn into red blocks?"
	wait(5)
	plrGui.Texted.TextLabel.Visible = false
end)

Third.Touched:Connect(function(plr)
	local plrGui = plr.PlayerGui
	plrGui.Texted.TextLabel.Visible = true
	plrGui.Text.TextLabel = "???:I have so much questions"
	wait(5)
	plrGui.Texted.TextLabel.Visible = false
end)

Fourth.Touched:Connect(function(plr)
	local plrGui = plr.PlayerGui
	plrGui.Texted.TextLabel.Visible = true
	plrGui.Text.TextLabel = "???:What if-"
	wait(5)
	plrGui.Texted.TextLabel.Visible = false
end)

It’s because you have to check if the instance that touched the part is actually a player. It realistically can be anything.

This code efficiently checks if a player touched the part.

First.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild('Humanoid') ~= nil then -- If the instance which touched the part is a character, then
        local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
        local PlayerGui = Player:WaitForChild('PlayerGui')
        -- The rest of your code
    end
end)
1 Like