How would I add players to this script?

Here is a script I found on the DevForum, but I want to add it so that the receptionist can add someones username to the end of the command to teleport them. Here’s the script:

local players = game:GetService("Players")
local Group = id_here
local Rank = rank_here

players.PlayerAdded:Connect(function(plr)
    plr.Chatted:Connect(function(msg)
        if msg == "!backstage" and plr:GetRankInGroup(Group) >= Rank then
			plr.Character:SetPrimaryPartCFrame(CFrame.new(Vector3.new(10,10,10)))
        end
    end)
end)

You’re going to have split the string.

Read more:

How would I do that?

Split this string & then follow the example.

Would this work?

string.split("abc _ def", "_")

I don’t think you understand it.

Input

local input = "Hello You "
local values = input:split(",")
print(values[1], values[2])

Output

Hello, You

Yeah, I don’t understand. I can YouTube it?

You could try, I think it’s in some tutorials.

1 Like

I was watching a tutorial and they did

local arguments = string.split(message, "")

Would that work if I removed the local arguments thing to make it:

plr.Chatted:Connect(string.split(msg, "")

No, you would want to do it like this.

local players = game:GetService("Players")
local Group = id_here
local Rank = rank_here

players.PlayerAdded:Connect(function(plr)
    plr.Chatted:Connect(function(msg)
        local arguments = string.split(msg, "")
        end
    end)
end)

could i do this as it has the command in it?

Okay, so update:

This works, it just doesn’t work if I put the username after -training (i customised it a bit)

local players = game:GetService("Players")
local Group = id_here
local Rank = rank_here

players.PlayerAdded:Connect(function(plr)
    plr.Chatted:Connect(function(msg)
local arguments = string.split(msg, "")
        if msg == "!backstage" and plr:GetRankInGroup(Group) >= Rank then
			plr.Character:SetPrimaryPartCFrame(CFrame.new(Vector3.new(10,10,10)))
        end
    end)
end)
1 Like

I think that this should work with player usernames. Let me know if it helps.

local players = game:GetService("Players")
local Group = ID_Here
local Rank = Rank_Here 

players.PlayerAdded:Connect(function(plr)
	plr.Chatted:Connect(function(msg)
		if string.find(msg, "!backstage") and plr:GetRankInGroup(Group) >= Rank then
			local arguments = string.split(msg, " ")
			local PlayerToTP = players:FindFirstChild(arguments[2])
			if PlayerToTP == nil then
				warn("No player given or not found!")
			else
				PlayerToTP.Character:SetPrimaryPartCFrame(CFrame.new(Vector3.new(10,10,10)))
			end
		end
	end)
end)
1 Like

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