Trying to team nearest player prisoner

  1. When clicking textbutton, it will team nearest player prisoner.

  2. Teams yourself prisoner.

Local Script:

local player = game.Players.LocalPlayer
local players = game.Workspace:WaitForChild("Players")

local rs = game:GetService("ReplicatedStorage")
local folder = rs:WaitForChild("remotes")
local name = script.Parent.Parent.Username
	local Players = game:GetService("Players")
	local LocalPlayer = Players.LocalPlayer

			function Open()
	local Character = LocalPlayer.Character
	local HumanoidRootPart = Character and Character:FindFirstChild("HumanoidRootPart")
	if not (Character or HumanoidRootPart) then return end

	local TargetDistance = math.huge
	local Target

	for i,v in ipairs(Players:GetPlayers()) do
		if v ~= LocalPlayer and v.Character and v.Character:FindFirstChild("HumanoidRootPart") then
			local TargetHRP = v.Character.HumanoidRootPart
			local mag = (HumanoidRootPart.Position - TargetHRP.Position).magnitude
			if mag < TargetDistance then
				TargetDistance = mag
				Target = v

Server Script:

local rs = game:GetService("ReplicatedStorage")
local folder = rs:WaitForChild("remotes")


		Target.Team = game.Teams.Prisoner

Add a check to ignore yourself if that is the case. Example:

if NearestPlayer.Name == LocalPlayer.Name then
    --"Ignore and skip to the next player."

Edit: Please don’t post your scripts multiple times, just edit your previous post.

I’ve fixed that, but now I am trying to figure out how I would make if you put a time in a text label, how would you wait how long that text label says


I tried it, it puts them on the team for one second then takes them off

What did you input into the TextBox?

I tried 10, 10000 and so on and it just doesn’t wait

Try this as a diagnosis:


Does this put them on the team for 10 seconds? If not, that isn’t the case and I don’t know what else to tell you without the code and some sort of error.

Yes, it does I don’t know why it isn’t doing it with the label

So it just puts them on the team and removes them immediately or after 1 second? If immediately, check the location of it and try again, make sure the value is still in the TextBox, also try print the TextBox.Text just before wait and see what it says.

Just fixed it, thanks for your help.

Mark whichever reply as the solution so that other people can see that it’s resolved.

I have one more question, how would I detect if the textbox is empty? Would it just be if TextBox.Text = “” then

Yes, that is the correct way to check.