My game isn't working with more than one player

I am creating a power simulator, I created the training area, when I enter I start to gain status, when I leave it I stop gaining status, it works well in roblox studio, but when I published it in roblox and joined my friend it doesn’t work , it is reported that there is no player in the training area

iam alone work, but on server with more than 1 player

See, not working, this print was supposed to be printed if player isnt on the area

Part code :

    --Variables
local Part = workspace.Endurance0
local players = game:GetService("Players")
local trainingM = require(game.ServerStorage.TrainingFiles.TrainingModule)
local Zone = require(game.ServerStorage.TrainingFiles.ZoneModule)
local debounce = false
local waitTime = 1
local newZone = Zone.new(workspace.Endurance0)

while true do
  wait(waitTime)
  
  local playersInZone = newZone:getPlayers()
  local playersInZoneDictionary = {}
	for _, plr in pairs(playersInZone) do
		playersInZoneDictionary[plr] = true
	end
  
    for _, plr in pairs(players:GetChildren()) do
	  if playersInZoneDictionary[plr] then
		  print("here"..plr.Name)
		    if not trainingM.GetTraining() then
			   
		    else
		    if trainingM.GetTraining()[plr.UserId]["Training"] == false then
			   print("IAM HERE")
			   trainingM.SetTraining(plr,true)
			   trainingM.Training(plr,50,Part,"Endurance")
			   print("IAM HERE 2")
		    end
		    end
		  
	      	                   
	  else	
		    if not trainingM.GetTraining() then
			   
		    else  	
		    if trainingM.GetTraining()[plr.UserId]["Training"] == true then
			   print("i cant be here")
			   trainingM.SetTraining(plr,false)
			   trainingM.StopTraining(plr)
		    end
		    end
		  end
	  end
end

TrainingModule code :

    local training = {}
local trainingValues = {
	 ["Training"] = false
}

local StartTraining = game.Workspace:WaitForChild("StartTraining")
local StopTraining = game.Workspace:WaitForChild("StopTraining")

local module = {}

    function module.New(p)
	   training[p.UserId] = trainingValues
    end
    
    function module.SetTraining(player,value)
	  if value == nil then
		training[player.UserId] = nil
	  else
	    training[player.UserId]["Training"] = value
	  end
    end

    function module.GetTraining() 
	      return training
    end
   
    function module.Training(player,amount,Part,Stat)
		         StartTraining:Fire(player,amount,Part,Stat)
    end

    function module.StopTraining(player)         
		         StopTraining:Fire(player)         
    end

return module

ServerScriptService code :

    -- services
local Players = game:GetService("Players")
local Version = 1
local DataService = game:GetService("DataStoreService")
local PlayerData = DataService:GetDataStore("SimPowerStore_"..Version)
local MaxAttempts = 3 
local StartTraining = game.Workspace:WaitForChild("StartTraining")
local StopTraining = game.Workspace:WaitForChild("StopTraining")
local TrainModule = require(game.ServerStorage.TrainingFiles.TrainingModule)
local Zone = require(game.ServerStorage.TrainingFiles.ZoneModule)

-- variables
local ServerData = {}

--training events--
local AutoTraining = {}
local AutoTrainingValues = {
    ["Training"] = false
}

local function increaseStats(player,Amount,Stat)
	while true do
		wait(1)
		if AutoTraining[player.UserId]["Training"] == false then return end 
		
		ServerData[player.UserId]["Stats"][""..Stat]["Value"] = ServerData[player.UserId]["Stats"][""..Stat]["Value"] + 50
		print(ServerData[player.UserId]["Stats"][""..Stat]["Value"])
	end
end

local function checkIsTrainingArea(player,Amount,Part,Stat)
	 print("checkingg")
	 print(Amount)
	 AutoTraining[player.UserId]["Training"] = true
	 increaseStats(player,Amount,Stat)
end

local function stopTrainingF(player)	 
	AutoTraining[player.UserId]["Training"] = false
end

StartTraining.Event:Connect(checkIsTrainingArea)
StopTraining.Event:Connect(stopTrainingF)
	
--end training events--

local function DataRetry(DataFunction,...)
        local Tries = 0
        local Data = nil
        local Success,Message = false,nil
        local Args = {...}
        while Tries < MaxAttempts and not Success do
            Tries = Tries + 1
            Success,Message = pcall(function() Data = DataFunction(unpack(Args)) end)
            if not Success then wait(1) warn("DataRetry Failed:",Message) end
        end
        
        if not Success then
	       warn("Data not found")
        else
	       print("Data Found")
        end
          
        return Data
    end


local function newData()
    return {
        ["Stats"] = {
	       ["Strength"] = {
		      ["Value"] = 0;
		      ["Suffix"] = "";
		      ["Multiplier"] = 0;
		      ["Boost"] = 0;
	       };
	       ["Endurance"] = {
		      ["Value"] = 0;
		      ["Suffix"] = "";
		      ["Multiplier"] = 0;
		      ["Boost"] = 0;
	       };
	       ["Mind"] = {
		      ["Value"] = 0;
		      ["Suffix"] = "";
		      ["Multiplier"] = 0;
		      ["Boost"] = 0;
	       };
           ["Jump"] = {
		      ["Value"] = 0;
		      ["Suffix"] = "";
		      ["Multiplier"] = 0;
		      ["Boost"] = 0;
           };	
           ["Speed"] = {
		      ["Value"] = 0;
		      ["Suffix"] = "";
		      ["Multiplier"] = 0;
		      ["Boost"] = 0;
		   }    
        };
        ["Leard"] = {
	          ["Reputation"] = 0;
	          ["Rank"] = "Innocent";
        };
        ["Missions"] = {
	    
        };
        ["Skills"] = {
	
	    };
         
    }
end

local function Get(p)
	local Data = PlayerData:GetAsync("PlayerUserId_"..p.UserId)
	return Data
end

local function loadData(p)
    local data
    local Success,Error = pcall(function()
	    data = DataRetry(Get,p) 
    end)
     
	if Success then
		if not data then
          data = newData()
          print("Generating new data")
		end
	else
		p:Kick("Data not found pls Rejoin")
	end
	 
    ServerData[p.UserId] = data
end

local function teste(p)
	ServerData[p.UserId]["Leard"]["Reputation"] = 30
	print(ServerData[p.UserId]["Leard"]["Reputation"])
end 

local function saveData(p,SaveType)
    
        if ServerData[p.UserId] then
            local Success, Error = pcall(function() 
	           PlayerData:UpdateAsync("PlayerUserId_"..p.UserId, function(oldData)
		          return ServerData[p.UserId]
	           end) 
	
            end)
        
            if Success then
                warn(p.Name.." Data saved ")
            else
	            warn("Data wasn't saved for "..p.Name.." error "..Error)
            end

            if SaveType == "AutoSave" then
	
            else
            ServerData[p.UserId] = nil
            end
        end


            
end

local function loadLeardStats(p)
	local folder = Instance.new("Folder")
	
	local rank = Instance.new("NumberValue")
	rank.Name = "Rank"
	rank.Value = ServerData[p.UserId]["Leard"]["Rank"]
	rank.Parent = folder
	
	local reputation = Instance.new("NumberValue")
	reputation.Name = "Reputation"
	reputation.Value = ServerData[p.UserId]["Leard"]["Reputation"]
	reputation.Parent = folder
	
	folder.Name = "leaderstats"
	folder.Parent = p
end

Players.PlayerAdded:connect(function(p)
	TrainModule.New(p)
    loadData(p)
    loadLeardStats(p)
    teste(p) 
	AutoTraining[p.UserId] = AutoTrainingValues   
end)

game:BindToClose(function()	
	print("Closing")
	for _,p in pairs(Players:GetChildren()) do
		 stopTrainingF(p)
         DataRetry(saveData,p,"LeaveSave")
         TrainModule.SetTraining(p,nil)
         AutoTraining[p.UserId] = nil		
	end
	
end)
 
Players.PlayerRemoving:connect(function(p)
	   stopTrainingF(p)	
	   DataRetry(saveData,p,"LeaveSave")
	   TrainModule.SetTraining(p,nil)	
	   AutoTraining[p.UserId] = nil	
end)

while true do
	wait(180)	
		for _,p in pairs(Players:GetChildren()) do
         DataRetry(saveData,p,"AutoSave")
	end
end

local function x(Player)
	print("Connected")
end

The ZoneModule (isnt mine, is from a player that make a post on this forum) here is the post Zone+ v1 (deprecated) | Retrieving players within an area/zone

2 Likes

check out. did you put the part script?

Yes the First one Man, Part Code :slight_smile:

I’m going to check the script slowly

Thanks man, iam trying that almost 10 hours

put a script that indicates that every player can be there

Do the zones use touch events to detect players entering and leaving? That does not work with the character online unless there is TouchTransmitters in the body parts. Try adding TouchTransmitters or this will add them automatically:

character:WaitForChild("Humanoid").Touched:Connect(function() end)

Another option would be to use math to calculate if the player is in the region

Is a public module Zone+ v1 (deprecated) | Retrieving players within an area/zone

No, check Part Code, is working, detect when player enter on area and leave, the problem is my code, iam using tables to detect If player is training or not, but for Any reason with more than 1 player dont work

Bassicaly fire the StartTraning event and after Stop training event all times, probaly iam using tables wrong

What is the name of the game ? who has this problem

Is my game, the problem is that : when you enter on train área (the Green circle), you start get 50+ Stats ever 1 Second, when you leave the area you stop training work, if have only 1 player (see the First imagem, increasing 50), but If have 2 players or more dont work (see the 2 imagem), isnt increasing

As you can see it’s like I’m in the area and exiting it at the same time, even if using an if

Voy a ver los guiones nuevamente y voy a pedirle la opinión de un amigo que es srcipter

1 Like

If you give me a copy to open in studio I will try to figure it out

1 Like

Sorry i only can do that tomorrow

Okay i Will wait for your answer

1 Like

this is what my friend told me:I could only guess
But it seems
The script detect you already have training, but you arent there
Ofc yo ucan see that
And second guess is
It detect you arent there
Is either the Zone module is using Touched event
Thats my best guess
I cant really think straight since i have little idea on how it work interily

But work when have only 1 player on server that make no sense

Man check that Part

local function increaseStats(player,Amount,Stat)
    while true do
        wait(1)
        if AutoTraining[player.UserId]["Training"] == false then return end
       
        ServerData[player.UserId]["Stats"][""..Stat]["Value"] = ServerData[player.UserId]["Stats"][""..Stat]["Value"] + 50
        print(ServerData[player.UserId]["Stats"][""..Stat]["Value"])
    end
end
1 Like