My script give me an error and i dont know how to fix it

Hello, I’ve been trying to make my round system teleport me but it just prints and error! the error is: Argument 1 missing or nil in line 18! I don’t know how to fix it and it also doesn’t teleport me to the selected part what did i do wrong? :disappointed_relieved: my script:

local intermission = 30
local roundLength = 170

local inRound = game.ReplicatedStorage.InRound
local status = game.ReplicatedStorage.Status
local TC = game.ReplicatedStorage.TC

local function SetStatusMessage(message)
	status.Value = message
end
local function SetTextMessage(message)
	TC.Value = message
end


local function TeleportToSpawnPoint(spawnPoint)

	local character = game:GetService("Players"):GetPlayerFromCharacter()
	if character then
		local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
		if humanoidRootPart then
			humanoidRootPart.CFrame = spawnPoint
		end
	end
end

inRound.Changed:Connect(function()
	if inRound.Value == true then
		SetTextMessage("In Round")
		TeleportToSpawnPoint(game.Workspace.DropGame.RoundSpawn.CFrame)
	else
		SetTextMessage("In Lobby")
		TeleportToSpawnPoint(game.Workspace.Lobby.LobbySpawn.CFrame)
	end
end)

If somebody can help me please give me the lines of codes that i need for it to be fixed! Thank yall :smile::grinning:

9 Likes

First of all, you would be getting the player not the character and the error means just you didn’t insert what in the parantheses are.

3 Likes

Your script isn’t mentioning the character in

local character = game:GetService("Players"):GetPlayerFromCharacter()

To fix this, just insert the character. (this cannot be a non-player),
also your code wont work, just do:

local function TeleportToSpawnPoint(spawnPoint)
if spawnPoint == nil then return end
for _, v in pairs(game:GetService("Players"):GetPlayers()) do
v.Character.HumanoidRootPart.CFrame = spawnPoint
end
end
2 Likes

where should i insert the script/ replace it with?

1 Like

May you give an example fix of the code so i can kinda work with it better?

1 Like

you replace it with this code snippet inside the teleport function

1 Like

so should i replace it with this??

1 Like

I am just going to use a Touched Event so you understand on how to use it

local part = workspace.Part

part.Touched:Connect(function(hit) -- needed
	local char = hit.Parent -- essentially the character is "hitting" the part
	local player = game.Players:GetPlayerFromCharacter(char) --[[Basically:
	you would be getting the player from hit.Parent or char in the variable, so you got the local player]]
	
	if player then
		print(player.Name)
	end
end)

i understand nothing im so sorry im not really into coding fr

1 Like

I recommend you on how to get the character in some function and espacially the player, because that is what you need and @firasthe2 already told you on how to get the player with a for loop.

1 Like

sorry but i really dont know how to place it so should i just replace it with this?
:

local character = game:GetService("Players"):GetPlayerFromCharacter()
	if character then
		local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
		if humanoidRootPart then
			humanoidRootPart.CFrame = spawnPoint
		end
	end
1 Like

yes

charlimitisannoyingbutunderstanable

it still doesnt work what did i do wrong? my script again:

local function TeleportToSpawnPoint(spawnPoint)

	local function TeleportToSpawnPoint(spawnPoint)
		if spawnPoint == nil then return end
		for _, v in pairs(game:GetService("Players"):GetPlayers()) do
			v.Character.HumanoidRootPart.CFrame = spawnPoint
		end
	end
end

inRound.Changed:Connect(function()
	if inRound.Value == true then
		SetTextMessage("In Round")
		TeleportToSpawnPoint(game.Workspace.DropGame.RoundSpawn.CFrame)
	else
		SetTextMessage("In Lobby")
		TeleportToSpawnPoint(game.Workspace.Lobby.LobbySpawn.CFrame)
	end
end)
1 Like

I’ll make a comment and you do what it says ok?

local function TeleportToSpawnPoint(spawnPoint)

	local function TeleportToSpawnPoint(spawnPoint) -- COMPLETELY REMOVE THIS LINE
		if spawnPoint == nil then return end
		for _, v in pairs(game:GetService("Players"):GetPlayers()) do
			v.Character.HumanoidRootPart.CFrame = spawnPoint
		end
	end -- AND REMOVE THIS
end
1 Like

Replace this with your old code, just copy and paste this inside your code.

local intermission = 30
local roundLength = 170

local inRound = game.ReplicatedStorage.InRound
local status = game.ReplicatedStorage.Status
local TC = game.ReplicatedStorage.TC

local function SetStatusMessage(message)
	status.Value = message
end
local function SetTextMessage(message)
	TC.Value = message
end


local function TeleportToSpawnPoint(spawnPoint)
if spawnPoint == nil then return end
for _, v in pairs(game:GetService("Players"):GetPlayers()) do
v.Character.HumanoidRootPart.CFrame = spawnPoint
end
end

inRound.Changed:Connect(function()
	if inRound.Value == true then
		SetTextMessage("In Round")
		TeleportToSpawnPoint(game.Workspace.DropGame.RoundSpawn.CFrame)
	else
		SetTextMessage("In Lobby")
		TeleportToSpawnPoint(game.Workspace.Lobby.LobbySpawn.CFrame)
	end
end)
2 Likes

alr let me test it and ill tell you what happened. it works thank you so much

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.