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

How would i play a song when the creator joins?

Asked by 9 years ago

im trying to play a song when the player joins how would I do this?

1 answer

Log in to vote
4
Answered by
ImageLabel 1541 Moderation Voter
9 years ago

You can figure out who the creator of a game is using the CreatorId property of game. CreatorId, however, doesn't always return a player's userId, therefore, it's best to check to make sure that the enumerated type CreatorTypeis "user"

local function CreatorId(playerId)
    if playerId == game.CreatorId and game.CreatorType == Enum.CreatorType.User then
        return true
    end
end

-- The function would simply return true if the argument passed is in fact the creator's userId,
--and that the creator is a USER.... otherwise returns nil.

You would then use the **PlayerAdded **event to call the function CreatorId, with the userId property of every new player as argument, and execute whatever code comes next based on the whatever is returned.

local function CreatorId(playerId)
    if playerId == game.CreatorId and game.CreatorType == Enum.CreatorType.User then
        return true
    end
end

game:FindService('Players').PlayerAdded:connect(function (player)
    if CreatorId(player.userId) then
        --path to sound, play
    end
end)
Ad

Answer this question