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

Why Wont I Get Teleported to the map?

--Define varibles

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local ServerStorage = game:GetService("ServerStorage")

local MapsFolder = ServerStorage:WaitForChild("Maps")

local Status = ReplicatedStorage:WaitForChild("Status")

local GameLength = 60

local reward = 50

--Looping Out game

while true do
	
	Status.Value = "Waiting For More Players To Join"
	
	repeat wait(1) until game.Players.NumPlayers >=2
	
	Status.Value = "Intermission."
	wait(1)
	Status.Value = "Intermission.."
	wait(1)
	Status.Value = "Intermission..."
	
	local plrs = {}
	
	for i, player in pairs(game.Players:GetPlayers()) do
		if player then
			table.insert(plrs,player) --Add all players into the plrs table
		end
	end
	
	wait(2)
	
	local AvailableMaps = MapsFolder:GotChildren()
	
	local ChosenMap = AvailableMaps[math.random(1,#AvailableMaps)]
	
	Status.Value = ChosenMap.Name.."  Chosen"
	
	local ClonedMap = ChosenMap:Clone()
	ClonedMap.Parent = workspace
	
	--teleporting the players the the map chosen
	
	local SpawnPoints = ClonedMap:FindFirstChild("SpawnPoints")
	
	if not SpawnPoints then
		print("Error System Could Not Find Any Spawn Points!")
	end
	
	local AvailableSpawnPoints = SpawnPoints:GetChildren()
	
	for i, player in pairs(plrs) do
		if player then
			character = player.Character
			
			if character then
				--teleport time
				
				character:FindFirstChild("HumanoidRootPart").CFrame = AvailableSpawnPoints[1].CFrame
				table.remove(AvailableSpawnPoints,1)
				
				
				--Giving Players a sword
				
				local Sword = ServerStorage.Sword:Clone()
				Sword.Parent = player.Backpack
				
				local GameTag = Instance.new("BoolValue")
				GameTag.Name = "GameTag"
				GameTag.Parent = player.charecter
				
			else
				--there is no character
				if not player then
					table.remove(plrs,i)
				end
			end
		end
	end
	
	
	Status.Value = "Teleporting Players To Map"
	
	wait(2)
	
	for i = GameLength,0,-1 do
		
		for x,player in pairs(plrs)	do
			if player then
				
				if not character then
				--Left the game
			else
				if character:FindFirstChild("GameTage") then
					--They are alive
					print(player.Name.."Is still alive! ")
						else
					--the are not alive
					table.remove(plrs,x)
					print(player.Name.."Has Been Defeated")
				end
			end
		else
			table.remove(plrs,x)
			print(player.Name.."Has Benn Defeated")
	    end
	 end
Status.Value = "There are "..i.."secounds Left, and"..#plrs.."Players Remaining"

if #plrs ==1 then
	--least person left
	Status.Value = "The Winner Is".. plrs(1).Name
			plrs(1).leadrstats.CBucks.Value = plrs(1).leaderstats.CBucks.Value + reward
			break
		else if #plrs == 0 then
				Status.Value = "Nobody Has Won The Game"
				break
			elseif i == 0 then
				Status.Vakue = "Time Is Up"
				break
			end
		end
         end
   wait(1)
end

print("Game Has Ended")

for i, player in pairs(game.Players()) do
	character = player.Character
	
	if not character then
		--ingore them
	else
		if character:FindFirstChild("GameTag") then
			character.GameTag:Destory()
		end
		
		if player.Backpaack:FindFirstChild("Sword") then
			character.Backpack.Sword:Destriy()
		end
	end
	
	player:LoadCharacter()
end

   ClonedMap:Destroy()

Status.Value = "Game Ended"

wait(2)

2 comments

0

I can try but it's 161 lines...

0

there is no line 161

1 answer

I'm not sure how this isn't blatantly as simple as finding the player's Character using FindFirstChild() from the workspace, and then teleporting it if it is valid:

local model = workspace:FindFirstChild(player.Name)
if model then
	-- Teleport them
end

Also, your system is a terrible way of handling who has died and who hasn't. If you're trying to find who has died, then isn't it as easy as checking for their Humanoid's state (or checking if it's dead)?

character.Humanoid.StateChanged:Connect(function(state)
	if state == Enum.HumanoidStateType.Died then
		-- do something
	end
end)

4 comments

0

You can just use Humanoid.Died event. Also, you can use SetPrimaryPartCFrame if setting the HumanoidRootPart doesn't work.

0

sorry im a new scripter

0

That's why I mentioned "checking if it's dead", because StateChanged came to my mind first. Died is the easier way to do it. But, if it isn't broken, you don't fix it.

0

i have a request may you put the script in my script because i kinda dont know where to put it sorry for wasteing your time :(

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