idk why but the playeradded event don t fire, its located in ServerScriptService and its a server script. i tried different times on reworking the function but it still do nt fire in both game and studio.
Edit: i tested alot of things and found out that the code stop when i require the upgrade manager so now im looking to fix this
-- Services local ReplicatedStorage = game:GetService("ReplicatedStorage") local ServerScriptService = game:GetService("ServerScriptService") local Players = game:GetService("Players") -- Modules local ModuleScripts = ReplicatedStorage.Modules local GameSettings = require(ModuleScripts.GameSettings) local PlayerManagement = ServerScriptService.PlayerManagement local PlayerManagementModules = PlayerManagement.ModuleScripts local Data = ServerScriptService.Data local DataStore = require(Data.Modules.DataStore) local UpgradeManager = require(Data.Modules.UpgradeManager) -- Local Functions local function setupPlayerStats(player) local character = player.Character or player.CharacterAdded:wait() local humanoid = character:WaitForChild("Humanoid") local LeaderStats = Instance.new("Folder",player) LeaderStats.Name = "leaderstats" local OtherStats = Instance.new("Folder",player) OtherStats.Name = "OtherStats" local Money = Instance.new("IntValue",LeaderStats) Money.Name = "Money" local Reborn = Instance.new("IntValue",LeaderStats) Reborn.Name = "Reborn" local Cropfarmed = Instance.new("IntValue",LeaderStats) Cropfarmed.Name = "Crop Farmed" local Vip = Instance.new("BoolValue",OtherStats) Vip.Name = "Vip" local Donator = Instance.new("BoolValue",OtherStats) Donator.Name = "Donator" local Tutorial = Instance.new("BoolValue",OtherStats) Tutorial.Name = "Tutorial" local Pets = Instance.new("Folder",OtherStats) Pets.Name = "Pets" local Wheat = Instance.new("IntValue",OtherStats) Wheat.Name = "Wheat" local Carrots = Instance.new("IntValue",OtherStats) Carrots.Name = "Carrots" local Potatoes = Instance.new("IntValue",OtherStats) Potatoes.Name = "Potatoes" local Multyplier = Instance.new("IntValue",OtherStats) Multyplier.Name = "Multyplier" print("work") UpgradeManager:Update(player) end Players.PlayerAdded:Connect(setupPlayerStats)
The script are yielding and the event connect after the player joins, then the event will not get fired, to fix that you need to do a generic for loop
within all players that joined before the event fires, here is a example:
wait(2) local Players = game:GetService('Players') local function onPlayerAdded(player) print(player.Name, 'Joined!') end Players.PlayerAdded:Connect(onPlayerAdded) for _, player in pairs(Players:GetPlayers()) do print(player.Name, 'is already in game, calling onPlayerAdded!') coroutine.wrap(onPlayerAdded)(player) -- start a new thread and call the function! end
this will solve the problem
Fixed Code:
-- Services local ReplicatedStorage = game:GetService("ReplicatedStorage") local ServerScriptService = game:GetService("ServerScriptService") local Players = game:GetService("Players") -- Modules local ModuleScripts = ReplicatedStorage.Modules local GameSettings = require(ModuleScripts.GameSettings) local PlayerManagement = ServerScriptService.PlayerManagement local PlayerManagementModules = PlayerManagement.ModuleScripts local Data = ServerScriptService.Data local DataStore = require(Data.Modules.DataStore) local UpgradeManager = require(Data.Modules.UpgradeManager) -- Local Functions local function setupPlayerStats(player) local character = player.Character or player.CharacterAdded:wait() local humanoid = character:WaitForChild("Humanoid") local LeaderStats = Instance.new("Folder",player) LeaderStats.Name = "leaderstats" local OtherStats = Instance.new("Folder",player) OtherStats.Name = "OtherStats" local Money = Instance.new("IntValue",LeaderStats) Money.Name = "Money" local Reborn = Instance.new("IntValue",LeaderStats) Reborn.Name = "Reborn" local Cropfarmed = Instance.new("IntValue",LeaderStats) Cropfarmed.Name = "Crop Farmed" local Vip = Instance.new("BoolValue",OtherStats) Vip.Name = "Vip" local Donator = Instance.new("BoolValue",OtherStats) Donator.Name = "Donator" local Tutorial = Instance.new("BoolValue",OtherStats) Tutorial.Name = "Tutorial" local Pets = Instance.new("Folder",OtherStats) Pets.Name = "Pets" local Wheat = Instance.new("IntValue",OtherStats) Wheat.Name = "Wheat" local Carrots = Instance.new("IntValue",OtherStats) Carrots.Name = "Carrots" local Potatoes = Instance.new("IntValue",OtherStats) Potatoes.Name = "Potatoes" local Multyplier = Instance.new("IntValue",OtherStats) Multyplier.Name = "Multyplier" print("work") UpgradeManager:Update(player) end Players.PlayerAdded:Connect(setupPlayerStats) for _, player in pairs(Players:GetPlayers()) do coroutine.wrap(setupPlayerStats)(player) end
Hope it helped! :)