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 all players in a same location but not really?

local serverstorage = game:GetService("ServerStorage")
local playerlist = game:GetService("Players")
local tracksstorage = serverstorage:WaitForChild("Tracks"):GetChildren()
local workspacetrackfolder = game.Workspace.Track
local values = game.Workspace.Values
local racefolder = values.Race
local trackfolder = values.Track

local racestarted = racefolder.RaceStarted
local raceended = racefolder.RaceEnded
local racechoosed = trackfolder.RaceChoosed

game.Players.PlayerAdded:Connect(function(plr)
	local gui = plr.PlayerGui:WaitForChild("RaceSetup")
	local text1 = gui.TrackName
	while wait(0.2) do
		if racestarted.Value == true then
			print("a")
			if racechoosed.Value == false then
				print("Race choosed!")
				local choosedtrack = tracksstorage[math.random(1, #tracksstorage)]
				local currenttrack = choosedtrack:Clone()
				currenttrack.Name = choosedtrack.Name
				currenttrack.Parent = game.Workspace.Track
				currenttrack.CFrame = CFrame.new(game.Workspace.MapSpawner.Position)
				print("Ready for use!")
				text1.Text = "Track Name : "..currenttrack.Name
				racechoosed.Value = true
				local spawnpoint = currenttrack:GetChildren("Spawn")
				for i, players in pairs(game.Players:GetChildren()) do
				    players.Character.HumanoidRootPart.CFrame = CFrame.new(spawnpoint.Position) + Vector3.new(i*math.random(-2,2), i*2, 0)
					print("Teleported players!")
				end
			else
				print("Race already choosed")
			end
		end
	end
end)

31: invalid argument #1 to 'new' (Vector3 expected, got nil)

It doesn't teleport all of the players in the part's CFrame and i wanna do so they get teleported all over the part (like big spawnlocations usually do)

This is for a racing game.

1 answer

Well this is quite obvious it is saying the error is 31: invalid argument #1 to 'new' (Vector3 expected, got nil)

this is line 31

 players.Character.HumanoidRootPart.CFrame = CFrame.new(spawnpoint.Position) + Vector3.new(i*math.random(-2,2), i*2, 0)

and it expects vector3 so when you would want to move the cframe for humanoidrootpart instead of CFrame.new change it to Vector3.new

accept if helps

2 comments

0

i'll check that tommorow, gotta sleep.

0

It will for sure work thats your problem welp gn

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