So basically Everything use to work fine until I broke the scripts down into different ones. Here is the second script that inserts the value

game.Players.PlayerAdded:connect(function(p)
	local Alive = Instance.new("IntValue")
	Alive.Name = "Alive"
	Alive.Parent = p
for _,v in pairs(script:GetChildren()) do
v:Clone().Parent = p
end
end)

Here is the main script. Everything use to be fine until I made them in different scripts which I need. The Intermission and Teleport Function works fine but the Alive script is the only thing.

ERROR MESSAGE: 19:33:43.335 - Workspace.Main:6: attempt to index a nil value I understand what it means but I don't get what function p is doing wrong.

function Alive()
local a = 0
  local Last_Plr = nil
  for i,v in pairs(game.Players:GetPlayers()) do
        if v:findFirstChild("IntValue").Name == "Alive" then
          local alive = alive + 1
            Last_Plr = v

    if alive == 1 then
        local Message = Instance.new("Message", workspace)
        Message.Text = Last_Plr.Name.." is the last player left!"
wait(3)
Message:remove()
    end
end
end
end




function teleport()
	  for _,v in next, game.Players:GetPlayers() do
	v.PlayerGui.GUI.TextLabel.Text = "Teleporting Players!"
wait(1)
local target = CFrame.new(-35, 16.9, 17.4) 
for i, player in ipairs(game.Players:GetChildren()) do
    player.Character.Torso.CFrame = target + Vector3.new(0, i * 5, 0)
    
	   
end
end
end






function Intermission()
for i = 20,0,-1 do 
    wait(1) ;
    for _,v in next, game.Players:GetPlayers() do
        v.PlayerGui.GUI.TextLabel.Text = "Spleef is Starting in : "..i.. " Seconds...";
    end
end

end

while true do
Intermission()
wait(0.1)
teleport()
wait(0.1)
Alive()



end

1 comment

0

EDIT: Btw the Intvalue is popping up in the Player