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

Why won't the message for this disappear? (ANSWERED)

Asked by 8 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.
_G.Players = game:GetService("Players")

for i,v in pairs (game.Players:GetPlayers()) do
    if v.Name == "RadiantSolarium" and v:IsA("Player") then
        local M = Instance.new("Message", game.Workspace)
        M.Text = "The Mighty Pickle has arrived!"
    end
end

The message that spawns won't de-spawn.

1 answer

Log in to vote
1
Answered by
Discern 1007 Moderation Voter
8 years ago

This is only running right when the server is started. If you are not the first player to join the server, then the script will not notice you entered the game because it will never run again.

To fix this, we need to create a function. We have to use the PlayerAdded event so the function fires when any player enters the game. Then we can check if the player's name is RadianSolarium and create the message from there..

_G.Players = game:GetService("Players")

function playerEntered(player)
    if player.Name == "RadiantSolarium" then
        local M = Instance.new("Message", game.Workspace)
        M.Text = "The Mighty Pickle has arrived!"
        wait(4)
        M:Destroy()
    end
end

game.Players.PlayerAdded:connect(playerEntered)

Here is more information on functions. Here is more information on events. Here is more information on PlayerAdded.

If I helped you out, be sure to accept my answer!

Ad

Answer this question