Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can a person being detained, be teleported to a specific X,Y on the press of a text button?

I want to make a script where if a player gets detained, they get teleported to a certain X,Y using HumanoidRootPart when the person detaining the player presses a “Jail” TextButton. I have a slight idea of how to do it but not sure how to do it to only a specific person that’s in cuffs.

I would have to make a script in the jail text button which would teleport the player cuffed to a certain X,Y. Example: game.Players.PlayerCuffed.Character.HumanoidRootPart.CFrame = CFrame.new(0, 0, 0)

The thing I don’t know how to do, is for it only to affect the player that is detained not all the players. Basically I just need to create a variable that defines the cuffed player. Example: local PlayerCuffed = ………. So then I can make it only affect the cuffed player. I know this is kinda hard to understand but yeah I just need something to define the cuffed player apart from the rest of the players. Thank you for your time!

1 answer

Hey DrTryarus685, I hope your day is going well. It was kind of hard to understand what you're truly trying to achieve. Here are a few functions that might aid you with comments.

function Cuff(player) -- I personnaly would create a cuff function to check wether the player is cuff or not.

	local Cuff = Instance.new('StringValue') -- Create a simple StringValue.
	Cuff.Name = 'Cuff' -- Name the StringValue "Cuff" or anything you want.
	Cuff.Parent = player -- Parent the StringValue to the player. This would label the player as a cuffed player.

end

function UnCuff(player) -- I added this function just incase you would want to uncuff the player.
	
	if player:FindFirstChild("Cuff") then -- I check if the player has cuffs on.
		player:FindFirstChild("Cuff"):Destroy() -- if the conditional statement is true, I remove them.
	end
	
end


function MoveCuffedPlayer(player,location) -- This function is to move/teleport the cuffed player. The parameters contain the player and the location. The location must be a vector3 Value.
	
	if player:FindFirstChild("Cuff") then -- I first check if the player has cuffs on. If so...
		
		local Character = player.Character -- From here I define the character.
		local HumanoidRootPart = Character.HumanoidRootPart -- Next, I get the humanoidRootPart.
		
		HumanoidRootPart.CFrame = CFrame.new(location) -- I change the CFrame of the CUFFED player humanoidRootPart.
		
	end
	
end

--Here's an example--

task.wait(1)

Cuff(game.Players['zacdave'])

task.wait(5)

MoveCuffedPlayer(game.Players['zacdave'],Vector3.new(5,5,5))

task.wait(3)

UnCuff(game.Players['zacdave'])


Hopefully this helps!

2 comments

0

So after seeing the script you provided, I think I didn’t provide sufficient information. So I want to make like a script that goes inside of a tool that when you click your mouse on a person in-game, they get teleported infront of you and they can’t move but you can move them. Then, if you press a text button that is on screen the player that is infront of you gets sent to the location.

0

I know how to make everything else work I just need a variable to define the player that is infront of me (which I clicked on and IsCuffed) For example: local CuffedPlayer = game.Players.CuffedPlayer and local JailButton = script.Parent

This discussion is preserved as it was. New answers, comments, and votes are closed.