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? 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
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
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 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.
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
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)
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
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)