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

how to teleport player to specify location?

So i want my script to choose between some places that i choose and it gives me this error

Workspace.spawn.teleport.Script:18: bad argument #1 (Vector3 expected, got string) Stack Begin Script 'Workspace.spawn.teleport.Script', Line 18 - function onTouch Stack End

so it said like expect vector3 got string how can i fix that? here is a script

-- places i want to add for random tp
local mesto0 = Vector3.new(1,1,1)
local mesto1 = Vector3.new(2,2,2)

--choose random place
local function RN()
	math.randomseed(tick())
	local brojr = math.random(1)
	local brojm = ("mesto"..brojr)
	return brojm
end

--check if player and then tp player to random place
local function onTouch(part)
	local Player = part.parent and part.parent:FindFirstChild("Humanoid") and part.parent.Humanoid.Health > 0 and game.Players:GetPlayerFromCharacter(part.parent)
	if Player then
		part.parent.HumanoidRootPart.CFrame = CFrame.new(RN()) --tp
		print("Touched by " .. part.parent:GetFullName())  --say who touched
	return Player
	end
end

script.Parent.Touched:Connect(onTouch) --when touched call function onTouch

1 answer

so i fixed it by changing some things i replace locations with arrays so now i have one array in another that are locations

after that all left to do is optimize script for array and boom all work just like i wanted

-- places i want to add for random tp
local mesto = 
{  --     X,Y,Z
	b1 = {3,2,3},
	b2 = {13,2,13},
}

--choose random place
local function RN()
	math.randomseed(tick())
	local brojr = math.random(2)
	local brojm = (mesto["b"..brojr])
	return brojm
end

--check if player and then tp player to random place
local function onTouch(part)
	local Player = part.parent and part.parent:FindFirstChild("Humanoid") and part.parent.Humanoid.Health > 0 and game.Players:GetPlayerFromCharacter(part.parent)
	if Player then
		local Mesto = RN()
		part.parent.HumanoidRootPart.CFrame = CFrame.new(Vector3.new (Mesto[1],Mesto[2],Mesto[3])) --tp
	return Player
	end
end

script.Parent.Touched:Connect(onTouch) --when touched call function onTouch

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