Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 1 year ago
Edited 1 year ago

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

Log in to vote
0
Answered by 1 year ago
Edited 1 year ago

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
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. manith513 121 — 1y
Ad
Log in to vote
0
Answered by
manith513 121
1 year ago

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.

0
its used with a serverscript masilasi2008 10 — 1y
Log in to vote
0
Answered by 1 year ago

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)

Answer this question