I'm having a bit of trouble with a command

So I am trying to create a command that will allow administrators to jail other players. However, I am not too sure where I went wrong. Here is my script:

local prefix = ":"
local group = 8708530 -- current beta tester group
game.Players.PlayerAdded:connect(function(plr)
	local newJailedVal = script.HolderVals.JailedCopy:Clone()
	newJailedVal.Name = "Jailed"
	newJailedVal.Value = false
	newJailedVal.Parent = game.Workspace:WaitForChild(plr.Name)
	
	plr.Chatted:connect(function(message)
		local msg = message:split(" ")
		if msg[1] == prefix.."jail" and plr:GetRankInGroup(group) >= 9 then
			local target = msg[2]
			if game.Workspace:WaitForChild(target).Jailed.Value == false then
				return nil
			else
				target.Character.HumanoidRootPart.CFrame = workspace.Jail.Teleporter.CFrame*CFrame.new(0,3,0)
			end
		end
	end)
end)

Well, Iā€™m assuming itā€™s something wrong with how the character is being teleported. But Iā€™m not sure how to fix it.

Could you tell us what error is being produced?

What is the error youā€™re getting?
Also, teleporting the character should be done like;

target.Character.HumanoidRootPart.CFrame = CFrame.new(workspace.Jail.Teleporter.Position)
1 Like

@ZoomSummit
Iā€™m only receiving a Stack around Line 13.

Screen Shot 2020-12-23 at 12.19.01 PM

if game.Workspace:WaitForChild(target).Jailed.Value == false then

Also I edited the part about positioning.

Infinite yeld possibleā€¦
That would mean it does not find your target?
It would be a little helpful if I could see the yellow error, but Iā€™m assuming either the ā€˜Jailedā€™ BoolValue is not being found or the ā€˜targetā€™ but I highly doubt it is the target.

2 Likes

It said ā€œInfinite yield possibleā€ because I typed my username in wrong.

Iā€™m not sure how the value isnt being found because when I join the game, the value shows up in inside my character. Screen Shot 2020-12-23 at 12.23.59 PM

Gotta ask, does a localscript add your ā€˜Jailedā€™ value or a server script? I canā€™t quite think of another issue.

The server script gives the jailed value.

Oh. I recommend that you would add the value inside of the player and not the character, that way you could use it even if the character is dead/respawned/nonexistant.

I always put my values inside the player.
From there, you could fire below to access it.

game:GetService('Players')[target].Jailed.Value

Try doing this and see if you get any error.
on a quick note, I forgot to ask if the value is a boolean or a string. I assume it is a boolean but just making sure

1 Like

I didnā€™t get an error this time. But it still didnā€™t work. It must be something wrong with how I teleported the character.

Do you know how I can get the players character from the player again? Maybe I can try it like that.

I suggest appending a print to each these two, to make sure your script gets to that part and remove them later.

			if game.Workspace:WaitForChild(target).Jailed.Value == false then
                           -- print('a')
			return nil
		else
                          -- print('b')
			target.Character.HumanoidRootPart.CFrame = workspace.Jail.Teleporter.CFrame*CFrame.new(0,3,0)
		end
1 Like

Screen Shot 2020-12-23 at 12.34.47 PM

Nope, it didnt get to that part at all.

Yeah, because Jailed.Value was false in your case.

There is nothing to set Jailed.Value to true.

1 Like

OHH WAIT I CONFUSED MYSELF. It only teleports the player when the jailed value is set to trueā€¦ which is the direct opposite of what Iā€™m trying to do :man_facepalming:

Happens. Anyhow, I hope this helped you learn something new & hopefully it will work!

1 Like

I basically told the script to do nothing if the player wasnā€™t jailed :joy:

I did! Thank you both! I will use these methods in the future.

2 Likes