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

script doesn t teleport players back when round is over.?

i had i problem. im a youtuber and im a basic coder! i draw a simple code that works but sometimes its doesn't work! if someone win sometimes thats not destroying the map and teleports to lobby.

local ok
local s = script.Stat
local vals = game.ReplicatedStorage.vals
t = 0
while true do
	local plrs = game.Players:GetChildren()
	if #plrs > 0 then			
	t = 20
	repeat
		t = t-1
		s.Value = "Intermission.. "..t
		wait(1)
	until t == 0
	s.Value = "Game starting!"
	wait(2)
	local mapselect = game.ReplicatedStorage.Games:GetChildren()
	local choose = math.random(1,#mapselect)
	curnum = 0
	for i =1,#mapselect do
		curnum = curnum +1
		if curnum == choose then
			mapselect[i]:Clone().Parent = workspace
			curmap = mapselect[i].Name
			s.Value = "We'll be playing "..mapselect[i].Name
			ok = true
		end
	end
	wait(3)
	if ok == true then
		
	local plrs = game.Players:GetChildren()
	for i = 1,#plrs do
		local num = math.random(1,16)
		plrs[i].Character.Head.CFrame = CFrame.new(workspace.Teleports["Part"..num].Position)
		plrs[i].Character.Parent = workspace.Ingame
		end
	end
	t=100
	repeat
		t = t-1
		s.Value = t.." seconds left"
		wait(1)
		local ingame = workspace.Ingame:GetChildren()
	until t ==0 or vals.Winner.Value ~= "" or #ingame == 0
	if vals.Winner.Value ~= "" then
		s.Value = vals.Winner.Value.. " has won!"
		game.Players[vals.Winner.Value].leaderstats.Points.Value = game.Players[vals.Winner.Value].leaderstats.Points.Value +50
		game.Players[vals.Winner.Value].leaderstats.Wins.Value = 	game.Players[vals.Winner.Value].leaderstats.Wins.Value +1
		vals.Winner.Value = ""
		ok = false
	else
		s.Value = "No one has won! LMAO"
		ok = false
	end
	wait(3)
	if ok == false then
	local ingame = workspace.Ingame:GetChildren()
	for i =1,#ingame do
		local plr = game.Players:GetPlayerFromCharacter(ingame[i])
		plr:LoadCharacter()
		if ok == false then
		local plrs = game.Players:GetChildren()
	for i = 1,#plrs do
		local numspawn = math.random(1,16)
		plrs[i].Character.Head.CFrame = CFrame.new(workspace.Spawn["Part"..numspawn].Position)
		plrs[i].Character.Parent = workspace.Ingame
		ok = true
		end
		end
		end
	end
	wait(4)
	workspace[curmap]:Destroy()		
	else
		s.Value = "2 player are needed to play!"
		wait(1)
		end
end

formatted code

1 comment

0

Please format your code and tell me where is the error.

1 answer

plrs[i].Character.Head.CFrame = CFrame.new(workspace.Teleports["Part"..num].Position)

You wrote "Part"..num inside Teleports[], but script expects a number, an index number. You can try like:

local pos = workspace.Teleports:FindFirstChild("Part"..num) -- or if that not works you can try using tostring(num) instead of num, I am not sure
plrs[i].Character.Head.CFrame = CFrame.new(pos.Position)

And same thing at the teleporting back, but Spawn instead of Teleports, because I saw you used that there.

Hope this helps

8 comments

0

now its always saying no has won! LMAO

0

I can't help you in that, I didn't touched that code, I don't know what variable is S and vals.

0

At line21, try elseif vals.Winner.Value == "" then...

1

@Miniller if they don't give you the entire code then don't bother answering the question, it saves your time

0

"CFrame expects at least three arguments" if you put a Vector3 in a CFrame that's one argument and CFrame works with only one argument

0

so i have to replace CFrame to Vector3?

0

@MCAndRobloxUnited btw now I see he gave it but it's not formatted

0

-1 for saying CFrame expects 3 arguments when the OP's cframe constructor is perfectly fine

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