So, I'm pretty new to Lua overall and I was making a deathrun game to practice Lua.
Everything has gone well until here. I want to make this pick out a killer and teleport the killer to a different location, but I don't know how.
Here is the code, I got it from the wiki:
local oldMessage = "" local minPlayers = 1 -- Players required to start a round. function teleportAllPlayers() local target = CFrame.new(workspace.RunnerLevel1.TeleportTarget.Position) for i, player in ipairs(game.Players:GetChildren()) do player.Character.Torso.CFrame = target + Vector3.new(0, i * 5, 0) player.Playing.Value = 1 --add an offset of 5 for each character end end function message(message) if oldMessage ~= message then oldMessage = message print(message) end end function playersCurrentlyPlaying() for i, player in ipairs(game.Players:GetChildren()) do if player.Playing.Value == 1 then return true end -- If player is alive, shows that the player is playing. end return false end game:GetService('Players').PlayerAdded:connect(function(player) player.CharacterAdded:connect(function(character) character:WaitForChild("Humanoid").Died:connect(function() -- If the player dies, this shows the player is no longer playing. player.Playing.Value = 0 end) end) local playing = Instance.new("IntValue", player) playing.Value = 0 playing.Name = "Playing" end) while(true) do wait(5) -- Time until a round starts if #game.Players:getPlayers() >= minPlayers then if playersCurrentlyPlaying() then message("Waiting for the current game to end...") else message("There are enough players for a new game! Teleporting...") -- If there is enough players, the round can start. wait(4) teleportAllPlayers() end else message("Waiting for more players...") end -- If there isn't enough players, the round will not start. end
Any help would be greatly appreciated.
You need to pick from a table of contestants, for example:
contestants = {} player = game.Players.LocalPlayer game.Players.PlayerAdded:connect(function(player) table.insert(contestants, player) end) --Pick random person to be the Killer killer = contestants[math.random(1, #contestants)] --Teleport if player == killer then game.Workspace[player.Name].Torso.CFrame = [location of killer spawn].CFrame else game.Workspace[player.Name].Torso.CFrame = [location of non-killer spawn].CFrame end