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

Teleport script for specific players not working properly?

Hey there! Very amateur scripter who knows basic stuff and mainly uses youtube tutorials to make scripts! I'm having a bit of trouble getting this one to work. It doesn't properly run despite not having any noticeable flaws in ROBLOX studio, can anybody help me out with this?

local placeID_1 = 6305834065
local TeleportService = game:GetService("TeleportService")
local Owner = "FrigidusIncendium, Strawberrymlqq"

		local function onPartTouch(otherPart)
			script.Parent.Touched:Connect(onPartTouch)
	local player = game.Players:GetPlayerFromCharacter(otherPart.Parent)
	if player == Owner then
		TeleportService:Teleport(placeID_1, player)
			end
		end

Thanks!

3 comments

0

What is it supposed to do?

0

Script is supposed to detect whether or not either of the two players are touching the brick, then teleport them to another game

0

Bit of a PSA but please indent your code so we can read it properly <3

1 answer

✓ Accepted answer

You should use a table instead of a string, if you don't know what a table is, it's something you can store many different values inside such as strings, booleans, numbers, etc. If you store your name (or others) inside the table you can then use table.find() whenever a player touches the part to check if their name is inside the table, if it doesn't find their name inside the table then it'll return nil, otherwise, if it does find their name in the table then it'll return the index position of it.

local placeID_1 = 6305834065
local TeleportService = game:GetService("TeleportService")
local Owner = {"FrigidusIncendium", "Strawberrymlqq"}

local function onPartTouch(otherPart)

	local player = game.Players:GetPlayerFromCharacter(otherPart.Parent)

	if player then 
		if table.find(Owner, player.Name) then
			TeleportService:Teleport(placeID_1, player)
		end
	end
end

script.Parent.Touched:Connect(onPartTouch)

5 comments

0

This works perfectly and taught me something new! Thank you very much!

0

No problem. Make sure to mark this as the answer to your question.

0

I'm sorry, but I'm having a little bit of trouble figuring out how. Is it cool if I get a quick explanation, I wanna mark this as answered

0

There should be a button somewhere around my answer that you can click to accept this as the answer to your question.

0

Thank you very much again! Take care!

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