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

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

Asked by
Djinous 45
8 years ago

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

Log in to vote
2
Answered by
Uroxus 350 Moderation Voter
8 years ago

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!

0
Could also do instead of name, creatorId JamesLWalker 297 — 8y
0
Thank you, this works! Djinous 45 — 8y
0
I've already accepted it, but do you know how to also get it to play music? Djinous 45 — 8y
Ad
Log in to vote
-1
Answered by 8 years ago

This is NOT a request site.

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

0
Added a piece of code I tried. Djinous 45 — 8y
0
You switched around Np and PlayerEntered. Put Np in the parentheses at the bottom bubbaman73 143 — 8y
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. M39a9am3R 3210 — 8y
Log in to vote
-1
Answered by 8 years ago
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)

Answer this question