I am stuck on this issue, and I can’t figure out how I will solve it.
game.Players.PlayerRemoving:Connect(function(player)
local folder = game.ReplicatedStorage:WaitForChild(player.Name) --I didnt use findfirstchild cus of attempt to index nil
local id = player.UserId
local tool = folder:FindFirstChildOfClass("StringValue").Value
print(tool)
end)
Are you searching in the ReplicatedStorage for a folder named (player.name)?
Try putting print statements before each line like
game.Players.PlayerRemoving:Connect(function(player)
print("Removing ", player.Name)
local folder = game.ReplicatedStorage:WaitForChild(player.Name)
print(folder)
local id = player.UserId --what is this line for?
local tool = folder:FindFirstChildOfClass("StringValue").Value
print(tool)
end)
--> Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
--> Functions
local function PlayerAdded(player: Player) --> Create The Folder
local Folder = Instance.new("Folder")
Folder.Name = player.Name
local Tool = Instance.new("StringValue")
Tool.Name = "Tool"
Tool.Value = "Tool"
Tool.Parent = Folder
Folder.Parent = ReplicatedStorage
end
local function PlayerRemoving(player: Player) --> Get The Folder & Tool
local Folder = ReplicatedStorage:FindFirstChild(player.Name)
local Tool = Folder:FindFirstChild("Tool")
print(Tool.Value)
end
for _, v in pairs(Players:GetPlayers()) do
PlayerAdded(v)
end
Players.PlayerAdded:Connect(PlayerAdded)
Players.PlayerRemoving:Connect(PlayerRemoving)
It could be race conditions and the script running after the first player joins the game so it doesnt create the folder, so thats why you always wanna loop through all the current players before you connect PlayerAdded
local function PlayerRemoving(player: Player) --> Get The Folder & Tool
local Folder = ReplicatedStorage:FindFirstChild(player.Name)
local Tool = Folder:FindFirstChild("Tool")
This didn’t work because player.Name was never assigned?
Is player.name referencing the path to the player and then the name property? If so, the problem could be from you trying to find children inside a name.
local folder = game.ReplicatedStorage:WaitForChild(player.Name) -- Name Is String, or Child?
local tool = folder:FindFirstChildOfClass("StringValue").Value -- Trying to find children through name