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

PlayerHasJoined - Help?

Asked by 9 years ago

What this script does is look for a player named "JustARegularGuy804" which is me, then make a GUI pop up for 10 seconds, then disappear.

if game.Players.Name == "JustARegularGuy804" then
    script.Parent.RegularGuy.Visible = true
    wait(10)
    script.Parent.RegularGuy.Visible = false
end

The GUI seems to just stay there permanently, plus I have 2 of these to see if it's broken, used the SAME script, with different names, but it seems to still not work.

By the way, the TextBox name is "RegularGuy".

0
Please help. JustARegularGuy804 25 — 9y

2 answers

Log in to vote
0
Answered by
User#3 0
9 years ago

In order to have a GUI popup for only a user named JustARegularGuy804 use a script like follows.

game.Players.PlayerAdded:connect(function(plr) --PlayerAdded Event | Fires when a new player joins the server
    if(plr.Name == "JustARegularGuy804") then --We compare the new players name with your name
        plr.CharacterAdded:connect(function() --Once this player spawns, show the GUI
            script.Parent.Visible = true
            wait(10)
            script.Parent.Visible = false
        end)
    end
end)

This script should be under the object you wish to hide.

I should say that nothing in the PlayerGUI is private. If they know how, they can read all the contents.

This will also show up every time they respawn. If you don't want that, add a debounce to check if they've spawned before.

Futher Reading: PlayerAdded Event CharacterAdded Event

0
THANK YOU! I could not figure it out, and I FORGOT about functions. JustARegularGuy804 25 — 9y
0
Could you check it as the right answer? Maybe a vote up? User#3 0 — 9y
1
You should not put this in the gui. There is no need to have multiple copies of the script. You should just put this on the server and reference the gui through PlayerGui. NotsoPenguin 705 — 9y
0
That's a good thought. Thanks. User#3 0 — 9y
Ad
Log in to vote
0
Answered by
ImageLabel 1541 Moderation Voter
9 years ago

You are checking if the service Players's Name property is equal to yours. In order to get your idea working, you would have to keep track of all entrances. Therefore, you would want to use a RBXScriptSignal or event to run your check.

The PlayerAdded event will be best in this context... However, it doesn't work as expected in LocalScripts, so you would have to make sure that it's in a regular (server) script.

game.Players.PlayerAdded:connect(function (player)
    --check
end)

then, you could check if the name of the player matches yours.

if player.Name == 'mine' then
    --clone
end

finally, you would want to actually clone the gui from somewhere other than StarterGui, into the player's or everyone's PlayerGui. Altogether, your script should look something like this..

local storage = game:GetService('ReplicatedStorage') local guiFile = storage:WaitForChild('RegularGuy') local name = 'mine' game.Players.PlayerAdded:connect(function (player) if player.Name == mine then local gui = guiFile:clone()

    -------- If for one player ----------
    gui.Parent = player:WaitForChild('PlayerGui')
    -------- If for all players ----------
    --loop through `game.Players`
    for i, peer in ipairs(game.Players:GetPlayers()) do
        --parent gui to peer's playerGui
        gui.Parent = peer:WaitForChild('PlayerGui')
    end
end

end

0
I'd remove the reference to RBXScriptSignal, as it's irreverent to this question. Saying Event would be fine. User#3 0 — 9y
0
How could it be irrelevant if they are both similar? It doesn't hurt to tell things the way they are :D ImageLabel 1541 — 9y

Answer this question