You can write your topic however you want, but you need to answer these questions:
-
**I am currently attempting to make a system where when a player loads into the game it clones a “Factory” from ReplicatedStorage and renames the cloned Factory to their UserId (Helps identify the player’s Factory easier for my TP System), then I have a teleporting system that checks all the cloned factories and checks if the cloned factory contains a part named (*LocalPlayer’sID) and if it does then it teleports the Player to his individual factory. **
-
It is saying its failed to index nil with ‘FindFirstChild’ when referencing checking if the child of the “DefaultFactory” is the player’s UserID
(“FactoryLoader”) LOCATED IN “ServerScriptService” V
local dFac = game:GetService("ReplicatedStorage"):WaitForChild("Factories").DefaultFactory
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("FactoryDS")
local Players = game:GetService("Players")
local Nodes = game:GetService("Workspace"):WaitForChild("FactoryNodes")
Players.PlayerAdded:Connect(function(player)
local factoryLoaded = false
for _, location in Nodes:GetChildren() do
if not location:FindFirstChild("DefaultFactory") then
if factoryLoaded then break end
local success, data = pcall(function()
return DataStore:GetAsync(tostring(player.UserId))
end)
if success and data and data["OwnedFactory"] then
local LoadFac = dFac:Clone()
LoadFac.Parent = location
LoadFac:PivotTo(location.CFrame)
LoadFac.DefaultFactory.Name = tostring(player.UserId)
factoryLoaded = true
print("FactoryPerPlayerLoaded")
end
end
end
end)
(“Script”) LOCATED IN Workplace under “Static” V
local Players = game:GetService("Players")
local Factories = game:GetService("Workspace").FactoryNodes
local TouchPart = script.Parent
TouchPart.Touched:Connect(function(touched)
if touched.Parent:IsA("Model") and touched.Parent:FindFirstChild("Humanoid") then
local Player = Players:GetPlayerFromCharacter(touched.Parent)
if Player then
local FacNodes = Factories:GetChildren()
for _, Node in FacNodes do
if Node:FindFirstChild("DefaultFactory"):FindFirstChild(tostring(Player.UserId)) then
local FacTeleporter = Node:FindFirstChild("DefaultFactory").ReplicatedTeleporter
local HumanoidRP = Player.Character:FindFirstChild("HumanoidRootPart")
if FacTeleporter then
if HumanoidRP then
HumanoidRP.CFrame = FacTeleporter.CFrame
end
end
end
end
end
end
end)
I know this is a hefty ask but it could just be that I’m referencing or structuring my code wrong, so any help or tips are appreciated! TY