Help with this script?

Because there’s nothing in your new thread :joy:

local Maps = game.ServerStorage.Maps:GetChildren()
local ChosenMap =	Maps[math.random(1, #Maps)]
local ChosenMapB = ChosenMap:Clone() 
ChosenMapB.Parent = workspace


local path = ChosenMapB
local spawns = ChosenMapB.PlayerSpawns -- spawns folder

game:GetService("Players").PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)

		local humanoid = character:WaitForChild("Humanoid")-- yeilds/stops the script until the humanoid is loaded

		humanoid.Died:Connect(function()
			task.spawn(function() -- spawns in a new "thread"
				local rand = Random.new():NextInteger(1,#spawns:GetChildren()) -- Makes a random number

				local randspawn = spawns:GetChildren()[rand] 

				character:PivotTo(CFrame.new(randspawn.Position+Vector3.new(0,10,0)))-- positions the character on the spawn
			end)
		end)
	end)
end)

I do?

Don’t use math.random as it is superseded by Random.new()

Random.new()? I haven’t heard of that before…

Dude tell me when do you want the player respawn when it dies… Tell me the exact time.

You basically use it like this:

local n = Random.new():NextInteger(min,max)

--or
local n = Random.new():NextNumber(min,max)

right as the player respawns, the player needs to go to a random spawn in a spawn folder in the map.

local ChosenMap =	Random.new():NextInteger(1, #Maps)     [math.random(1, #Maps)]

is this how i was supposed to do it? Because this errors as: ServerScriptService.Script:2: attempt to index number with number

Then try adding a task.wait(game:GetService("Players").RespawnTime + 0.5) before positioning the character

1 Like

No, it’s supposed to be like this:

local ChosenMap = Maps[Random.new():NextInteger(1,#Maps)]
--ok now you're in the map
local your_time = 600 -- the period of time when the player dies and respawns
local time = tick()

--so now we want to check if the time is less than your time
if tick-time<=your_time then
  --your code here
else return end

Hope it works

I wouldn’t suggest using tick() as it is deprecated. Use os.clock() instead.

It’s not deprecated but it’s kind of outdated

Is respawn time a property of player??

Does not work still, no errors though.

local Maps = game.ServerStorage.Maps:GetChildren()
local ChosenMap = Maps[Random.new():NextInteger(1,#Maps)]
local ChosenMapB = ChosenMap:Clone() 
ChosenMapB.Parent = workspace


local path = ChosenMapB
local spawns = ChosenMapB.PlayerSpawns -- spawns folder

game:GetService("Players").PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)

		local humanoid = character:WaitForChild("Humanoid")-- yeilds/stops the script until the humanoid is loaded

		humanoid.Died:Connect(function()
			task.spawn(function() -- spawns in a new "thread"
				local rand = Random.new():NextInteger(1,#spawns:GetChildren()) -- Makes a random number

				local randspawn = spawns:GetChildren()[rand] 
				task.wait(game:GetService("Players").RespawnTime + 0.5)
				character:PivotTo(CFrame.new(randspawn.Position+Vector3.new(0,10,0)))-- positions the character on the spawn
			end)
		end)
	end)
end)

I want to apoligize and thank you all for working so hard to help me with this even though i am a actual idiot. I appreciate all the help. Im sorry this is taking so long to figure out.

tick() is deprecated, however that doesn’t mean it won’t work. The term “deprecated” in rohlox means that it still works, but you shouldn’t use it for new work.

It’s ok dude try reaching other Devs too.

1 Like

It’s a property of game.Players, not the player object.

1 Like

I wonder what was the root cause of the problem.