Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Module not requiring, help?

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)

5 comments

0

check if it errors

0

No errors related to this script ,the only errors i get are the one that do nt find the objects that this script make

0

Posted a answer

0

Accept yHasteeD answer if it answered your question. Do it by pressing the accept button below his answer.

0

read comments of the answer

1 answer

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! :)

4 comments

0

Thanks so much

0

Okay tested it but no changes it still not fire / the objects such as leaderstats are not there

0

so i played a bit with your code and figured out this, your example not fire when in a folder in serverscriptservice, i tried to use the fixed code you made and still do nt work so i tried to test use some wait around but still not working , i have no clue

0

Maybe any of your modules start a infinite loop, starting the infinite loop will not run the main code

This discussion is preserved as it was. New answers, comments, and votes are closed.