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

How to fix the ServerScriptService.important script :3:16: attempt to index nil with 'CFrame'?

Asked by 3 years ago
Edited 3 years ago

well When I play long my Game Stopped

(ServerScriptService.important script :3:16: attempt to index nil with 'CFrame')

This is the script

local roundLenght = 2
local intermissionLenght = 2
local InRound = game.ReplicatedStorage.InRound
local Status = game.ReplicatedStorage.Status

local LobbySpawn = game.Workspace.LobbySpawn

local AvailableSpawnPoints = game.Workspace.SpawnPoints:GetChildren()

InRound.Changed:Connect(function()
    if InRound.Value == true then
        for _, player in pairs(game.Players:GetChildren())do
            wait(0.02)
            game.Lighting.Part1:clone().Parent = game.Workspace
            local char = player.Character
            char.HumanoidRootPart.CFrame =  AvailableSpawnPoints[1].CFrame + Vector3.new(0,10,0)
            table.remove(AvailableSpawnPoints,1)
            wait(2)
            game.Lighting.Blade:clone().Parent = player.Backpack
        end
    else
        for _, player in pairs(game.Players:GetChildren())do
            local char = player.Character
            char.HumanoidRootPart.CFrame = LobbySpawn.CFrame
            wait(0.1)
            game.Workspace.Part1:Remove()
            wait(0.1)
            game.Players:FindFirstChild("Blade", true):Remove()

        end
    end
end)


local function roundTimer()
    while wait() do
        for i = intermissionLenght, 1, -1 do
            InRound.Value = false
            wait(1)
            Status.Value = "intermission: "..i.." seconds left! Get Ready to do an Icy Fight!"
        end
        for i = roundLenght, 1, -1 do
            InRound.Value = true
            wait(1)
            Status.Value = "Game: "..i.." seconds left!"
        end
    end
end

spawn(roundTimer)

Can you help me? please thank you

1 answer

Log in to vote
0
Answered by
cancle5 120
3 years ago
Edited 3 years ago

I'm not that sure since I can't really see the explorer but is the spawns a model??? You can't get the CFrame of a model. If it has to be a model you can use. PrimaryPart.CFrame.

(Here is the code edited if it's a model.) Also, if that's the problem add a PrimaryPart Also, you don't need to use a PrimaryPart you can use Spawn.Part

local roundLenght = 2
local intermissionLenght = 2
local InRound = game.ReplicatedStorage.InRound
local Status = game.ReplicatedStorage.Status

local LobbySpawn = game.Workspace.LobbySpawn

local AvailableSpawnPoints = game.Workspace.SpawnPoints:GetChildren()

InRound.Changed:Connect(function()
    if InRound.Value == true then
        for _, player in pairs(game.Players:GetChildren())do
            wait(0.02)
            game.Lighting.Part1:clone().Parent = game.Workspace
            local char = player.Character
            char.HumanoidRootPart.CFrame =  AvailableSpawnPoints[1].PrimaryPart.CFrame + Vector3.new(0,10,0)
            table.remove(AvailableSpawnPoints,1)
            wait(2)
            game.Lighting.Blade:clone().Parent = player.Backpack
        end
    else
        for _, player in pairs(game.Players:GetChildren())do
            local char = player.Character
            char.HumanoidRootPart.CFrame = LobbySpawn.CFrame -- If this is a model too do the same LobbySpawn.PrimaryPart.CFrame
            wait(0.1)
            game.Workspace.Part1:Remove()
            wait(0.1)
            game.Players:FindFirstChild("Blade", true):Remove()

        end
    end
end)


local function roundTimer()
    while wait() do
        for i = intermissionLenght, 1, -1 do
            InRound.Value = false
            wait(1)
            Status.Value = "intermission: "..i.." seconds left! Get Ready to do an Icy Fight!"
        end
        for i = roundLenght, 1, -1 do
            InRound.Value = true
            wait(1)
            Status.Value = "Game: "..i.." seconds left!"
        end
    end
end

spawn(roundTimer)
Ad

Answer this question