I need help with my round script

  1. What do you want to achieve?
    I want to make my sword fight game(by me and original) and I have a bug with it that I can’t fix.

  2. What is the issue?
    The part on the script that is bugging is where I want to teleport the players to the map
    this script may look vaguely familiar to alvinbloxes sword fight game, but I promise I planned this myself I am just coding it on my own. I am just using some things that alvinblox did in his tutorial. like using the status value for displaying messages.

here’s the code and look on the comments to see where is the error.

-- define variables
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local StarterGui = game:GetService("StarterGui")
local Status = ReplicatedStorage:WaitForChild("StatusValue")
local MapsFolder = ServerStorage:WaitForChild("Maps")

-- first we need to create the loop
while true do
	wait(5) -- wait so then the script dosen't crash 
	
	Status.Value = "Waiting for enough players..."
	
	repeat wait() until game.Players.NumPlayers >= 1
	
	Status.Value = "Intermission"
	
	
	-- Add all players in table in put them in it
	local Plrs = {}
	
	for i,player in pairs(game.Players:GetChildren()) do
		if player then
			table.insert(Plrs,i)
		end
	end
	
	-- choose a random map and clone it and put it in the workspace. 
	local AvaibleMaps = MapsFolder:GetChildren()
	
	local ChosenMap = AvaibleMaps[math.random(1,#AvaibleMaps)]
	
	Status.Value = ChosenMap.Name.."chosen"
	
	ChosenMapClone = ChosenMap:Clone()
	ChosenMapClone.Parent = game.Workspace
	
	-- teleport the players to the map
	
	-- first make a table with all of the avaible spawn points. 
	local SpawnPositions = ChosenMap:FindFirstChild("SpawnPoints")
	
	local SpawnPoints = SpawnPositions:GetChildren()
	
	
	-- start spawning the players
	for i,player in pairs(Plrs) do
		if player then
			
			character = player.Character -- it is erroring right here.
			
			if character then
				character:FindFirstChild("HumanoidRootPart").CFrame = SpawnPoints[1].CFrame
				table.remove(SpawnPoints,1)
			end
		else
			-- there is no avaible character so remove them.
			if not character then
				table.remove(Plrs,i)
				print("character no found")
			end
		end
	end
	
end

thank you for reading!

Try using this instead:

if character then
	character:PivotTo(SpawnPoints[1].CFrame)
	table.remove(SpawnPoints,1)
end

It’s not advised to set the CFrame of the HumanoidRootPart when trying to move the character model. Instead you can use PVInstance | Roblox Creator Documentation, which can move the model without needing a Model | Roblox Creator Documentation. I suspect that the tutorial you were using was outdated.

It is erroring on line 50 and it is saying ServerScriptService.RoundScript:50: attempt to index number with ‘Character’. I think the script dosen’t know what is the character. But thank you for teaching me a new thing! :smiley:

Well, the problem is the Plrs table that you made.
First, to fix the problem you need to change line 24 from

table.insert(Plrs,i)

to

table.insert(Plrs,player)

Second, Your code is really wordy. I think you should delete unnecessary parts of the code. For example, I don’t get why you need to set a table to keep the players when you can just use

 game.Players:GetPlayers()
1 Like

"

[quote=“O_devO, post:4, topic:1515175”]
Second, Your code is really wordy. I think you should delete unnecessary parts of the code. For example, I don’t get why you need to set a table to keep the players when you can just use

 game.Players:GetPlayers()

That is because that is the table containing the ready players because I am going to go through all of those players and I am going to add a tag into them. This is so then I can detect how many players are left in a round.

But I like to thank you for fixing my script :slight_smile:

it is now way much better and I like to thank you guys :slight_smile: