Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

What does "Attempt to index nil with 'Character' " mean?

so i'm having trouble teleporting all the players to a position of a part.

my code

while true do
	local status = game.ReplicatedStorage.Status
	local inter = game.ReplicatedStorage.Intermission
	status.Value = "Time until next round: "
	local plr = game.Players.LocalPlayer
	inter.Value = 30
	repeat
		inter.Value -= 1
		wait(1)
	until inter.Value == 0
	local Josh = game.ReplicatedStorage.Spawn:Clone()
	Josh.Parent = workspace
	game.Players.LocalPlayer.Character.HumanoidRootPart.Position = Josh.SpawnPoint.Position
	plr.Humanoid.WalkSpeed = 0
	status.Value = ""
	inter.Value = 3
	wait(1)
	inter.Value = 2
	wait(1)
	inter.Value = 1
	wait(1)
	inter.Value = 0
	status.Value = "Go!"
	wait(1)
	status.Value = ""
	Josh:Destroy()
	plr.Humanoid.WalkSpeed = 16
end

can you guys help? this is a server script btw

3 answers

✓ Accepted answer

to get all players use for loop to get all players

while true do
    local status = game.ReplicatedStorage.Status
    local inter = game.ReplicatedStorage.Intermission
    status.Value = "Time until next round: "
    inter.Value = 30
    repeat
        inter.Value -= 1
        wait(1)
    until inter.Value == 0
    local Josh = game.ReplicatedStorage.Spawn:Clone()
    Josh.Parent = workspace
for i, plr in pairs(game.Players:GetPlayers()) do
	local Character = plr.Character
		if Character then
			Character.HumanoidRootPart.CFrame = Josh.CFrame
			plr.Humanoid.WalkSpeed = 0
		end
end
    status.Value = ""
    inter.Value = 3
    wait(1)
    inter.Value = 2
    wait(1)
    inter.Value = 1
    wait(1)
    inter.Value = 0
    status.Value = "Go!"
    wait(1)
    status.Value = ""
    Josh:Destroy()
    for i, plr in pairs(game.Players:GetPlayers()) do
	local Character = plr.Character
		if Character then
			plr.Humanoid.WalkSpeed = 16
		end
end
end

1 comment

0

Yes thank you I was meaning to write something similar to this but I was on phone so I just put the steps hoping he would figure it out lol.

You can use LocalPlayer unless you're in a local script. If this is a local script, change it right now because you are screwing up the code for other players by having multiple local scripts. If you want to do what you are doing, use a for loop that loops through the players characters that teleports them.

1 comment

0

its used with a serverscript

You are unable to recieve the "LocalPlayer" by doing game.Players.LocalPlayer on a ServerScript, as that runs on the server.

There are multiple ways of receiving the player, for example, you could use events with parameters that returns the player.

EXAMPLE

game.Players.PlayerAdded:Connect(function(plr)
    player = plr
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.