Is it ok to have the same event in multiple scripts?

my question is exactly the title. let’s say you had multiple systems like a car system or whatever and u needed to get the players user ID on the server for different systems. would it be okay to have the PlayerAdded event in multiple server scripts?

atm i’m working on my block placement system for my game, i needed to access an attribute from my Plots folder on the server. i have the PlayerAdded in maybe another 2 scripts for different stuff.

if there’s a better way, i appreciate any help or feedback thanks!!

Placement module:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local UserInputService = game:GetService("UserInputService")

local IsServer = RunService:IsServer()
local Assets = require(ReplicatedStorage.Scripts.AssetsModule)

local Placement = {}
Placement.__index = Placement

function Placement.new(plot)
	local self = setmetatable({}, Placement)
	
	if IsServer then
		print("Server")
		self.PlotObjects = Instance.new("Folder")
		self.PlotObjects.Name = "PlotObjects"
		self.PlotObjects.Parent = plot
	else
		print("Client")
	end
	
	return self
end

return Placement

server script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Scripts = ReplicatedStorage:WaitForChild("Scripts")
local Placement = require(Scripts.Placement)

local function OnPlayerAdded(player : Player)
	local Plots = workspace.Plots
	
	for _, plot in pairs(Plots:GetChildren()) do
		local owner = plot:GetAttribute("owner")
		
		if owner == player.UserId then
			Placement.new(plot)
			return
		end
	end
end

game.Players.PlayerAdded:Connect(OnPlayerAdded)

Yeah.

As long as your code doesn’t interfere with other PlayerAdded event codes.

4 Likes

like @Average_FreeTooPlay said, there is no problem. However, one thing i can say for certain is that you should check whenever you really need the player added or not. For optimization reasons.

And lastly, if your playerAdded do the same thing, consider using a module script to make it easier for you to edit. (Which you already did, which is very good!)

2 Likes

@Average_FreeTooPlay @lamcellari

thank you guys so much for all your help! you all have been really insightful. :slight_smile:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.