Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago

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)
0
This can't be your only code, show us your variables. cmgtotalyawesome 1418 — 3y
0
u can try to make a variable of the playername local name = player.Name luxkatana 61 — 3y
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 Xapelize 2658 — 3y
0
How are you testing this? in studio? Benbebop 1049 — 3y

3 answers

Log in to vote
2
Answered by 3 years ago
Edited 3 years ago

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)
0
I hope it works now acediamondn123 147 — 3y
0
Yes this is right you probally got confused with c# cancle5 120 — 3y
Ad
Log in to vote
0
Answered by
xxaxxaz 42
3 years ago
Edited 3 years ago

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)
Log in to vote
0
Answered by
Benbebop 1049 Moderation Voter
3 years ago
Edited 3 years ago

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 +

Answer this question