I'm making a game for fun and I'm coding the MainFramework but with teleporting it says Attempted to index with a nil value:WaitForChild(), Can anyone help me?
Here's the code:
local EventsModule = require(script:WaitForChild("EventsModule"))
local MethodNames = {}
for MethodName, Method in pairs(EventsModule) do
if type(Method) == "function" then
table.insert(MethodNames, MethodName)
end
end
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Remotes = ReplicatedStorage:WaitForChild("Remotes")
local Values = ReplicatedStorage:WaitForChild("Values")
local Status = Values:WaitForChild("Status")
local timeBetweenEvents = 5
local AllPlates = ReplicatedStorage:WaitForChild("Plates"):GetChildren()
local minimumPlayers = 0
while true do
Status.Value = "Waiting for enough players!"
repeat wait(1) until game.Players.NumPlayers >= 1
Status.Value = "Intermission"
local Plates = ReplicatedStorage.Plates:Clone()
Plates.Parent = workspace
local Players = game.Players:GetPlayers()
local PlayersAlive = {}
local PlatesAlive = {}
for i, player in pairs(game.Players:GetPlayers()) do
local plate = Plates:FindFirstChild("Plates"..i)
local character = player.Character
local HumanoidRootPart = character:WaitForChild("HumanoidRootPart")
if HumanoidRootPart and #Players >= minimumPlayers then
HumanoidRootPart.CFrame = plate.CFrame * CFrame.new(0,3,0)
player.serverData.playerPlate.Value = i
local plateOwner = Instance.new("StringValue")
plateOwner.Name = "plateOwner"
plateOwner.Value = player.Name
plateOwner.Parent = plate
table.insert(PlayersAlive, player)
table.insert(PlatesAlive, plate)
for i, v in pairs(PlayersAlive) do print(i,v) end
character.Humanoid.Died:Connect(function()
print(player.Name.." has died")
table.remove(PlayersAlive, table.find(PlayersAlive, player))
table.remove(PlatesAlive, table.find(PlatesAlive, plate))
end)
end
end
for i, plate in pairs(Plates:GetChildren()) do
local plateOwner = plate:FindFirstChild("plateOwner")
if plateOwner.Value == nil then
plate:Destroy()
end
end
while #PlayersAlive > 0 do
wait(timeBetweenEvents)
local RandomMethodName = MethodNames[math.random(1, #MethodNames)]
local Method = EventsModule(RandomMethodName)
Method()
end
Plates:Destroy()
end

2 comments
Try using player.CharacterAdded:Wait() on line 37?
ok