How to make a !fail (player) command?

Fix this line.

Does that work? (This is random text because it has to be over 20 characters long)

Should I do a Connect to a function?

No No No.

game.Players.PlayerAdded:Connect(function(player) --When player joins get player instance.
	player.Chatted:Connect(function(msg) --Detect when the player joined chats and get the message text.
		local SplitMessage = msg:split(" ")
		if SplitMessage[1] == "!fail" then
			local NameOfPlayerToFail= SplitMessage[2]
			local PlayerToFail = game.Players:FindFirstChild(NameOfPlayerToFail)
		end
	end)
end)

It should look like this.

This is good though, that should work.

What do you think we do next.

FOund the error its alright

What?

It was just incorrect formatting, not any errors.

Oh I meant at the same time you pasted that in I realised I needed the other message:split

What?

Your still using the same “msg:split()”, I thought we discovered this a while ago?

So, let’s get on the same line.

This is the code we got:

game.Players.PlayerAdded:Connect(function(player) --When player joins get player instance.
	player.Chatted:Connect(function(msg) --Detect when the player joined chats and get the message text.
		local SplitMessage = msg:split(" ")
		if SplitMessage[1] == "!fail" then
			local NameOfPlayerToFail= SplitMessage[2]
			local PlayerToFail = game.Players:FindFirstChild(NameOfPlayerToFail)
		end
	end)
end)

What do you think we do next?

Do we need this?:

local PlayerToFail = game.Players:FindFirstChild(NameOfPlayerToFail)
1 Like

Yeh we do, do you know what that line does?

It finds the player?

Basically.

In deeper terms, it searches the Players Folder until it finds the Player with the same name as the NameOfPlayerToFail variable.

Any ideas what we do next? Feel free to say that you don’t know.

do we have to go into the game and find the ScreenGui in ServerStorage?

Well, we can clone it into the playerGui, or we can replicated storage (which is slightly more complex).

Which way would you like to use?

Maybe to save you time we could just do it in the playerGui.

1 Like

For sure, let’s try that.

Since it’s getting late & I should probably be getting to bed.

HOWEVER, if you don’t understand a line of code PLEASE tell me.

local PlayerGui = game.ServerStorage.Gui --Example


game.Players.PlayerAdded:Connect(function(player) --When player joins get player instance.
	player.Chatted:Connect(function(msg) --Detect when the player joined chats and get the message text.
		local SplitMessage = msg:split(" ")
		if SplitMessage[1] == "!fail" then
			local NameOfPlayerToFail= SplitMessage[2]
			local PlayerToFail = game.Players:FindFirstChild(NameOfPlayerToFail)
			local ClonedPlayerGui = PlayerGui:Clone()
			ClonedPlayerGui.Parent = PlayerToFail.PlayerGui
		end
	end)
end)

Oh okay. To be honest, I don’t really get the SplitMessages