Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

There's nothing in the output. Why is this not printing player.Name?

There's nothing in the output about this, please point out my error/s.

Players.PlayerAdded:Connect(function(player)
	PlayerCount.Value = PlayerCount.Value + 1
	print(PlayerCount.Value)
	print(player.Name + "has joined the game")
	
end)

4 comments

0

This can't be your only code, show us your variables.

0

u can try to make a variable of the playername local name = player.Name

0

Player parameter is set. It is useless to set another variable locate it player.Name if it's once use. Variables aren't important

0

How are you testing this? in studio?

3 answers

use ".." instead of "+"

so it should look like this:

game.Players.PlayerAdded:Connect(function(player) -- btw don't forget the define to game
    PlayerCount.Value = PlayerCount.Value + 1
	    print(PlayerCount.Value)
    print(player.Name.."has joined the game")
	 
end)

2 comments

0

I hope it works now

0

Yes this is right you probally got confused with c#

you forgot your local variable.

local PlayerCount.Value = 0

game.Players.PlayerAdded:Connect(function(player)
	PlayerCount.Value = PlayerCount.Value + 1
		print(player.Name.." has joined the game")

end)

if you want to use a intvalue instead

add a intvalue into workspace and name it PlayerCount. then do this script.

local PlayerCount = workspace.PlayerCount

game.Players.PlayerAdded:Connect(function(player)
	PlayerCount.Value = PlayerCount.Value + 1
		print(player.Name.." has joined the game")

end)

#Studio Load Order

When testing in studio, your player connects before any Scripts are run. This means PlayerAdded events will never be fired. It is recommended to write fallbacks for any PlayerAdded events.

Example

local RunService = game:GetService("RunService")
local Players = game:GetService("Players")

function playerAdded(callback)
	if RunService:IsStudio() then
		callback()
	else
		Players.PlayerAdded:Connect(callback)
	end
end

playerAdded(function() 
	print("fallback working")
end)

Also .. congregates strings not +

This discussion is preserved as it was. New answers, comments, and votes are closed.