How to make when a player says a word in the chat the sees a screen ui

Hello Developers, I tried to make that when a player say “/myinfo” in the chat a Gui appears on the player screen and I made this script but it dosen’t work for some reason and when I try it it doesn’t say any error in the console

local frame = game.StarterGui.ScreenGui.InfoGui

game.Players.PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(msg)
		if msg == "/myinfo" then
			frame.BackgroundTransparency = 0
			frame.UIStroke.Transparency = 0
			frame.Yes.BackgroundTransparency = 0
			frame.Yes.TextTransparency = 0
			frame.Yes.UIStroke1.Transparency = 0
			frame.Yes.UIStroke2.Transparency = 0
			frame.No.BackgroundTransparency = 0
			frame.No.TextTransparency = 0
			frame.No.UIStroke1.Transparency = 0
			frame.No.UIStroke2.Transparency = 0
			frame.TextLabel.BackgroundTransparency = 0
			frame.TextLabel.TextTransparency = 0
			frame.TextLabel.UIStroke1.Transparency = 0
		end
	end)
end)

If you can tell me what’s the problem and how to exactly fix it and write a script if you can, And if you want to help me fix the whole script I don’t know if the other part works but if it doesn’t work you can fix it too

local parent = script.Parent.Parent.Parent.Parent
local frame = game.StarterGui.ScreenGui.InfoGui

game.Players.PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(msg)
		if msg == "/myinfo" then
			frame.BackgroundTransparency = 0
			frame.UIStroke.Transparency = 0
			frame.Yes.BackgroundTransparency = 0
			frame.Yes.TextTransparency = 0
			frame.Yes.UIStroke1.Transparency = 0
			frame.Yes.UIStroke2.Transparency = 0
			frame.No.BackgroundTransparency = 0
			frame.No.TextTransparency = 0
			frame.No.UIStroke1.Transparency = 0
			frame.No.UIStroke2.Transparency = 0
			frame.TextLabel.BackgroundTransparency = 0
			frame.TextLabel.TextTransparency = 0
			frame.TextLabel.UIStroke1.Transparency = 0
			frame.Yes.MouseButton1Click:Connect(function()
				parent.CanCollide = true
				script.Parent.Parent.Parent.CanCollide = true
				parent.Transparency = 0
				parent.SurfaceGui.PlayerIsInGroup.TextTransparency = 0
				parent.SurfaceGui.PlayerIsVerified.TextTransparency = 0
				parent.SurfaceGui.Username.TextTransparency = 0
				parent.SurfaceGui.AccountAge.TextTransparency = 0
				parent.SurfaceGui.UserId.TextTransparency = 0
				script.Parent.Parent.Parent.Transparency = 0
				parent.SurfaceGui.Username.Text = "Username: @"..plr.Name
				parent.SurfaceGui.AccountAge.Text = "AccountAge: "..plr.AccountAge
				parent.SurfaceGui.UserId.Text = "UserId: "..plr.UserId
				local PlayerUserName = plr.Name

				local PlayerUserId = game.Players:GetUserIdFromNameAsync(PlayerUserName)
				if not PlayerUserId then return end
				local Image
				local success, errormsg = pcall(function()
					Image = game.Players:GetUserThumbnailAsync(PlayerUserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size100x100)
				end)
				if not success then
					warn(errormsg)
					return
				end
				if Image then
					script.Parent.Image = Image
				end
				if plr:IsVerified() then
					parent.SurfaceGui.PlayerIsVerified.Text = "PlayerIsVerified: Yes"
				else
					parent.SurfaceGui.PlayerIsVerified.Text = "PlayerIsVerified: False"
				end
				if plr:IsInGroup(16615541) then
					parent.SurfaceGui.PlayerIsInGroup.Text = "PlayerIsInGroup: Yes"
				else
					parent.SurfaceGui.PlayerIsInGroup.Text = "PlayerIsInGroup: False"
				end
				frame.BackgroundTransparency = 1
				frame.UIStroke.Transparency = 1
				frame.Yes.BackgroundTransparency = 1
				frame.Yes.TextTransparency = 1
				frame.Yes.UIStroke1.Transparency = 1
				frame.Yes.UIStroke2.Transparency = 1
				frame.No.BackgroundTransparency = 1
				frame.No.TextTransparency = 1
				frame.No.UIStroke1.Transparency = 1
				frame.No.UIStroke2.Transparency = 1
				frame.TextLabel.BackgroundTransparency = 1
				frame.TextLabel.TextTransparency = 1
				frame.TextLabel.UIStroke1.Transparency = 1
			end)
			frame.No.MouseButton1Click:Connect(function()
				frame.BackgroundTransparency = 1
				frame.UIStroke.Transparency = 1
				frame.Yes.BackgroundTransparency = 1
				frame.Yes.TextTransparency = 1
				frame.Yes.UIStroke1.Transparency = 1
				frame.Yes.UIStroke2.Transparency = 1
				frame.No.BackgroundTransparency = 1
				frame.No.TextTransparency = 1
				frame.No.UIStroke1.Transparency = 1
				frame.No.UIStroke2.Transparency = 1
				frame.TextLabel.BackgroundTransparency = 1
				frame.TextLabel.TextTransparency = 1
				frame.TextLabel.UIStroke1.Transparency = 1
			end)
		end
	end)
end)
8 Likes

You are grabbing the StarterGui, not the Player’s Gui.

local frame = game.StarterGui.ScreenGui.InfoGui

Reference the player’s GUI instead,

local frame = plr.PlayerGui.ScreenGui.InfoGui

Your method of checking the message is fine, but if you are using TextChatService(Non-Legacy), I would encourage you to use the TextChatCommand feature. I would check out the Documentation for TextChatCommand.

As another side note, I would build the UI as they load in to the game, instead of upon clicking a button(unless its to select another user’s info to view). I also recommend you change the Visible property for an entire frame, rather than setting transparency for everything.

2 Likes

It seems like you’re setting the transparency properties to 0 when showing the GUI and 1 when hiding it. While setting the transparency to 0 makes the elements visible, you also need to consider whether they are appropriately positioned and sized within the GUI frame. Additionally, the MouseButton1Click event connections for the Yes and No buttons should be placed outside of the plr.Chatted event to ensure they are only connected once.

If you’re not seeing any errors in the console, it’s possible that the script is not being triggered. Make sure the script is running and the event handlers are connected. You can add print statements inside the plr.Chatted event to help debug whether the event is being triggered when a player types “/myinfo”.

local frame = game.StarterGui.ScreenGui.InfoGui
local parent = script.Parent.Parent.Parent.Parent

local function ShowInfo(player)
    -- Show GUI and set properties
    frame.BackgroundTransparency = 0
    -- Set other GUI properties here
    
    -- Connect the button events
    frame.Yes.MouseButton1Click:Connect(function()
        -- Update GUI and perform actions on 'Yes' button click
    end)
    
    frame.No.MouseButton1Click:Connect(function()
        -- Update GUI and perform actions on 'No' button click
    end)
end

local function HideInfo()
    -- Hide GUI and reset properties
    frame.BackgroundTransparency = 1
    -- Reset other GUI properties here
end

game.Players.PlayerAdded:Connect(function(player)
    player.Chatted:Connect(function(msg)
        if msg == "/myinfo" then
            ShowInfo(player)
        end
    end)
end)

3 Likes

It still doesn’t work it says this error and I changed the script to this
image

local parent = script.Parent.Parent.Parent.Parent

game.Players.PlayerAdded:Connect(function(plr)
	local frame = plr.PlayerGui.ScreenGui.InfoGui
	plr.Chatted:Connect(function(msg)
		if msg == "/myinfo" then
			frame.BackgroundTransparency = 0
			frame.UIStroke.Transparency = 0
			frame.Yes.BackgroundTransparency = 0
			frame.Yes.TextTransparency = 0
			frame.Yes.UIStroke1.Transparency = 0
			frame.Yes.UIStroke2.Transparency = 0
			frame.No.BackgroundTransparency = 0
			frame.No.TextTransparency = 0
			frame.No.UIStroke1.Transparency = 0
			frame.No.UIStroke2.Transparency = 0
			frame.TextLabel.BackgroundTransparency = 0
			frame.TextLabel.TextTransparency = 0
			frame.TextLabel.UIStroke1.Transparency = 0
		end
	end)
	frame.Yes.MouseButton1Click:Connect(function()
		parent.CanCollide = true
		script.Parent.Parent.Parent.CanCollide = true
		parent.Transparency = 0
		parent.SurfaceGui.PlayerIsInGroup.TextTransparency = 0
		parent.SurfaceGui.PlayerIsVerified.TextTransparency = 0
		parent.SurfaceGui.Username.TextTransparency = 0
		parent.SurfaceGui.AccountAge.TextTransparency = 0
		parent.SurfaceGui.UserId.TextTransparency = 0
		script.Parent.Parent.Parent.Transparency = 0
		parent.SurfaceGui.Username.Text = "Username: @"..plr.Name
		parent.SurfaceGui.AccountAge.Text = "AccountAge: "..plr.AccountAge
		parent.SurfaceGui.UserId.Text = "UserId: "..plr.UserId
		local PlayerUserName = plr.Name

		local PlayerUserId = game.Players:GetUserIdFromNameAsync(PlayerUserName)
		if not PlayerUserId then return end
		local Image
		local success, errormsg = pcall(function()
			Image = game.Players:GetUserThumbnailAsync(PlayerUserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size100x100)
		end)
		if not success then
			warn(errormsg)
			return
		end
		if Image then
			script.Parent.Image = Image
		end
		if plr:IsVerified() then
			parent.SurfaceGui.PlayerIsVerified.Text = "PlayerIsVerified: Yes"
		else
			parent.SurfaceGui.PlayerIsVerified.Text = "PlayerIsVerified: False"
		end
		if plr:IsInGroup(16615541) then
			parent.SurfaceGui.PlayerIsInGroup.Text = "PlayerIsInGroup: Yes"
		else
			parent.SurfaceGui.PlayerIsInGroup.Text = "PlayerIsInGroup: False"
		end
		frame.BackgroundTransparency = 1
		frame.UIStroke.Transparency = 1
		frame.Yes.BackgroundTransparency = 1
		frame.Yes.TextTransparency = 1
		frame.Yes.UIStroke1.Transparency = 1
		frame.Yes.UIStroke2.Transparency = 1
		frame.No.BackgroundTransparency = 1
		frame.No.TextTransparency = 1
		frame.No.UIStroke1.Transparency = 1
		frame.No.UIStroke2.Transparency = 1
		frame.TextLabel.BackgroundTransparency = 1
		frame.TextLabel.TextTransparency = 1
		frame.TextLabel.UIStroke1.Transparency = 1
	end)
	frame.No.MouseButton1Click:Connect(function()
		frame.BackgroundTransparency = 1
		frame.UIStroke.Transparency = 1
		frame.Yes.BackgroundTransparency = 1
		frame.Yes.TextTransparency = 1
		frame.Yes.UIStroke1.Transparency = 1
		frame.Yes.UIStroke2.Transparency = 1
		frame.No.BackgroundTransparency = 1
		frame.No.TextTransparency = 1
		frame.No.UIStroke1.Transparency = 1
		frame.No.UIStroke2.Transparency = 1
		frame.TextLabel.BackgroundTransparency = 1
		frame.TextLabel.TextTransparency = 1
		frame.TextLabel.UIStroke1.Transparency = 1
	end)
end)
2 Likes

GUI’s can take time to load, so when the player is loading in, the server is trying to find something that doesn’t exist yet, I recommend you build the entire UI locally, and upon entering the message(the chat command), you can get the player and the player’s GUI. Or if you really want to check via the method you are doing, you can do

plr.PlayerGui.ChildAdded:Connect(function(child)
     if child.Name == "ScreenGui" then
        -- do stuff
     end
end)
3 Likes

It works correctly thank you so much for help!! :happy4:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.