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

GUI Player Teleporter? Help!

So I'm trying to make a GUI where you type in the players name you would like to teleport but so far nothing happens when I do so. The script is located in a button. I am sure I have got my player directly targeted.

playerselect = script.Parent.Parent.PlayerSelect.Text

script.Parent.MouseButton1Down:connect(function()
	local choose = script.Parent.Parent:FindFirstChild(playerselect.Text)
	for i,v in pairs(game.Players:GetChildren()) do
		if v.Name == choose then
			local target = v.Character.Torso.Position
			script.Parent.Parent.Parent.Parent.Parent.Parent.Character.Torso.Position = CFrame.new(target)
			
		end
	end
end)

1 answer

✓ Accepted answer

I notice a few errors with this.
The first might not be an issue, but it looks suspicious: is the TextBox PlayerSelect or Text? If it's PlayerSelect, then the line should be this:

playerselect = script.Parent.Parent.PlayerSelect

Next, the for loop is probably not necessary, since there will only be up to one player with the name specified. You can achieve the same effect with this:

local player = game.Players:FindFirstChild(playerselect.Text)
if player then
	-- Rest of code here.
end

Finally, you're trying to set the Position of the character (a Vector3 value) to a CFrame. Since this won't work, you should do this instead:

local target = player.Character.Torso.CFrame
-- The long .Parent chain is not necessary; note that this requires a local script to work.
game.Players.LocalPlayer.Character.Torso.CFrame = target

The complete code should look like this:

playerselect = script.Parent.Parent.PlayerSelect

script.Parent.MouseButton1Down:connect(function()
	local player = game.Players:FindFirstChild(playerselect.Text)
	if player then
		local target = player.Character.Torso.CFrame
		game.Players.LocalPlayer.Character.Torso.CFrame = target
	end
end)

4 comments

0

The one problem is would that work as a local script because Im making a game with FE

0

When your script needs to change something like a part's CFrame, a server script would be best. FilteringEnabled would mess up everything then.

0

There is surely a way to work around that.

0

Oh and btw i tried your code without FE in a local script and I got "Argument 1 missing or nil"

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