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

How would i play a song when the creator joins?

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

1 answer

✓ Accepted answer

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)

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