Why is my script not Working?

Hello, I think this is a really easy fix I just don’t know what the problem is because right now my code is

game.Players.PlayerAdded:Connect(function(player)
	print(player) 
	end)```

I don't know why it's not working is it because My script is in the Starter Gui? Thanks!
1 Like

Your probably need to put in serverScriptService.

Is that my only solution though and if so than why?

1 Like

Are you trying to make a gui visible when the player enter the game or something?

The goal is to find out how many players are in the game and if there are 2 or more then the text shoudl start counting down

1 Like

What text??, you just showed code for the playeradded event, your gonna need remotes and fire all clients updating the respective text labels to the countdown number

1 Like
local players = game:GetService("Players")

local count = script:WaitForChild("IntValue") -- make sure the script children is IntValue

players.PlayerAdded:Connect(function(player)
    print(player.Name)
    count .Value = count.Value + 1
end)

count.Changed:Connect(function(newValue) -- You can fire remote event here
   print(count.Value, newValue)
   if newValue >= (2) then
       -- Fires remote event here
   end
end)

players.PlayerRemoving:Connect(function(player)
    print(player.Name)
    count.Value = count.Value - 1
end)

Normal script in serverScriptService

1 Like

Yes I added that but That Is functioning and doesn’t have to do with my question

1 Like

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