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

How do I put a message on the screen if a certain player joins the game?

I want to make a script where a message will appear on the screen if I (Djinous) join the game. There a simple way I can do that?

EDIT: Forgot the code I already tried. There's probably something wrong with this, but I don't have the knowledge to find out what.

function onPlayerEntered(nP)
	if nP.Name == "Djinous" then
	m = Instance.new("Message", game.Workspace)
	m.Text = "The Commander has joined the game."
	wait(3)
	m:remove()
	end)
else
	end
end

game.Players.PlayerAdded:connect(onPlayerEntered)

3 answers

✓ Accepted answer

I find it easier to make the function and connect it on the same line, it just makes more sense when you have a script which does multiple things and end up with a load of connection lines at the bottom.


Solutions

This script 'broadcasts': "Player {PlayerName} has joined the game"

game.Players.PlayerAdded:connect(function(plr)
	local name = plr.Name
	msg = Instance.new("Message", game.Workspace)
	msg.Text = "Player "..name.." has joined the game"
	wait(3)
	msg:Destroy()
end)

If you wanted to make it so custom messages appear for specific people, like in your question then you'd do;


game.Players.PlayerAdded:connect(function(plr)
	local name = plr.Name
	if name == "Djinous" then
		msg = Instance.new("Message", game.Workspace)
		msg.Text = "The commander has joined the game"
		wait(3)
		msg:Destroy()
	end
end)

Conclusion

If this has answered your question please accept with the box on the right -> If it doesn't work (I didn't test this) then please do let me know and I'll fix it. Finally, if you want a better explanation please do ask!

3 comments

0

Could also do instead of name, creatorId

0

Thank you, this works!

0

I've already accepted it, but do you know how to also get it to play music?

This is NOT a request site.

But if you know how to code then just use PlayerAdded:connect(plr) and just use plr.Name

3 comments

0

Added a piece of code I tried.

0

You switched around Np and PlayerEntered. Put Np in the parentheses at the bottom

0

^ Wouldn't work. onPlayerEntered is the function that the event is trying to connect with connection to provide the nP variable. The script in the question is right. There's a misplaced ) though.

function var(plr)
local p = Instance.new("Message", workspace)
p.Text = (plr.Name .. " Has Joined!")
wait(2)
p:Destroy()
end
game.Players.PlayerAdded:connect(var)

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