Am I stupid? Why is this not working?

I… I just cannot properly describe this.

My PlayerAdded event doesn’t fire. Like at all.

I’m starting to lose my mind.

The script is in ServerScriptService with a module attached to it, and no other script is calling the playerAdded event.

I’ve added prints to the module part, since thats the only thing that happens when a player is added, but nothing. Nothing.

This has already happened to me before: My other topic. (Still unsolved)

Is my studio going crazy? Should I reinstall it? Or did I miss some small thing that blocked my entire code?

Please help me. I cannot continue working on my game if a mediocre error stops me. (well not quite since that is kinda the first step of the entire system)

Any help appreciated!

5 Likes

Usually this happens because the actual function binding part never gets ran. What happens before you try running this part of the code? Have you ensured that the line right before the connection gets printed?

I added a whole wait(1) before that event. Got no results.

Also, in my other places, it works fine.

however I need the player parameter so I can’t just get rid of the function…

Right before your game.Players.PlayerAdde:Connect() line add a print(“player added”) and make sure that runs. Note that a wait() before it at all might let you join the server before the code actually starts looking for the players that are joining.

Basically, there should be no waits before this code. And it should print something directly above it immediately

Nope. the output is blank.

No dont look at this this is cuz of the char limit

That means your code is never getting there. Does your module have an infinite loop or something? If it doesn’t return the rest of your code will never run.

1 Like

If you are testing in “Play Solo” mode, then you are probably experiencing the Player connecting to the game before the server-side scripts are run. This means the Player has already joined the game by the time the Script establishes the PlayerAdded event connection and therefore never fires.

In order to counteract this, you could call the function manually passing in any existing players at the run-time:

local Players  = game:GetService("Players")

function onPlayerAdded(player)

end

for _, player in Players:GetPlayers() do
   onPlayerAdded(player)
end
Players.PlayerAdded:Connect(onPlayerAdded)
1 Like

Check if the Module is returning correctly, and can you send a snippet of code before the PlayerAdded() function? It would help a lot!

Like i said, I added prints in the module. Its right in the first line, so no infinite loop should happen.

local plot = {}

plot.Random = Random.new()

local x = {}
local y = 200
local z = 300

local FIRST_OFFSET = 200

local function fillTable()
	for i=FIRST_OFFSET, 10000, 100 do
		wait()
		if not table.find(x, i) then
			table.insert(x, i)
		end
	end
end

fillTable()

function plot.new(player:Player)
	print("Called")
	local num = 1
	
	local chosen = x[num]
	
	table.remove(x, 1)
	
	local part = Instance.new("Part", game.ReplicatedStorage.Plots)
	part.Anchored = true
	part.Size = Vector3.new(50, 1, 50)
	part.TopSurface = Enum.SurfaceType.SmoothNoOutlines
	part.BottomSurface = Enum.SurfaceType.SmoothNoOutlines
	
	part.Position = Vector3.new(chosen, y, z)
	
	local tag = Instance.new("IntValue", part)
	tag.Name = "Position"
	tag.Value = chosen
	
	local plrValue = Instance.new("StringValue", part)
	plrValue.Name = "Player"
	plrValue.Value = player and player.Name or "LOL"
end

return plot

Now that I think about it, It might lie in the for loop.

That fill table function with the wait is going to take minutes. You’re doing a lot there. The player added code won’t work until that’s done. [oops. Didn’t notice you were incrementing by hundreds. Not minutes,]

2 Likes

Bruh…

I guess I am stupid.

I put an extra zero.

BRUH

1 Like

You can remove that wait. It’s a small enough loop you’re just adding delay unnecessarily (unless for some reason you need to specifically control the timing). My initial estimate was off because I didn’t notice the amount you were incrementing by. But any waits before your player added code can make it miss you while testing.

Hold on…

Thats still not the problem.

The playerAdded event still doesnt fire

i commented out the actual module call and I added a print.

Still doesnt fire. It doesnt seem like it.

game.Players.PlayerAdded:Wait()

game.Players.PlayerAdded:Connect(function(player)
	print("Player")
	--plot.new(player)
end)

2 Likes

@tlr22

lolololololololololololololol

1 Like

do not yield the script if you need to connect PlayerAdded event, the event will be connected after palyer joined because of wait🤦‍♂️

Still doesnt print sadly. I honestly think that I need to reinstall studio or something.

step 1: open empty baseplate
step 2: create Script inside ServerScriptService
step 3: put this into the Script (and make sure its enabled set to true)

print("playeradded print script loaded")
game:GetService("Players").PlayerAdded:Connect(function(plr)
       print(plr.UserId,"joined")
end)
print("playeradded print script loaded confirmed!")

Did you ever get it to print the line right above the connection?