I’m working on a script and I was running into issues on game.Players.PlayerAdded:Connect(function(plr)
my script is a local script, and i’m doing a main menu so obviously PlayerAdded is needed when making a main menu, but it is not reading it. I tested my script when i just put this on my script and nothing printed:
local SG = game:GetService("StarterGui")
local SP = game:GetService("StarterPlayer")
local PLRS = game:GetService("Players")
local UIS = game:GetService("UserInputService")
local FT = 0
local a = Enum.CoreGuiType.All
local function SetPlayer()
SG:SetCoreGuiEnabled(Enum.CoreGuiType.All, false)
SG:SetCore("ResetButtonCallback",false)
UIS.ModalEnabled = true
print("Finished Setting GUI")
end
-- ^ this is just stuff for my main menu, below is were i put my test,
-- as you can see i want it to print when the player is added, when i play the game
--nothing prints
game.Players.PlayerAdded:Connect(function(plr)
print("hi")
end)
its for a main menu, i want to make the player not move when the main menu is shown.
so i put the event game.players.playeradded fire the server when the player is added, and through the server it’ll change the speed and movement, etc
In the notes is suggests possible problems that you might encounter when in solo mode for example. Having said that .PlayerAdded is almost certainly not the best way to achieve what you want here.
Technically you can, it’s just that your Player alone won’t count as it being added to the Event since LocalScripts will run the moment a player is added in
If you wanted to do it server-sided, just reference a PlayerAdded event as its own in a regular Script
Doing it client-sided, you’d need to account for the LocalPlayer as well:
local YourPlayer = game.Players.LocalPlayer
game.Players.PlayerAdded:Connect(function(OtherPlayer)
print("Sanity check: ", OtherPlayer ~= YourPlayer) --This should print out true
end)
print("hi")