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

I am trying to ad a Owner entered the game script and its not working?

Asked by 9 years ago

function onPlayerEntered(newPlayer)

local name = game.Players.StringValue:clone()Parent = newPlayer name.Value = newPlayer.Name

if name.Value == "CorvetteLegend" then --replace roperson with your name

local m = Instance.new("Message") m.Parent = game.Workspace m.Text = "CorvetteLegend is in the game" --same here wait(10) m:remove() end end

1
1)Code block please. 2)I think you should add a bracket ")" after the last "end". 3)Try the "PlayerAdded" event instead. kudorey619 138 — 9y

2 answers

Log in to vote
-2
Answered by 9 years ago

You should make your code into a code block. I'll rewrite a whole script for you here though, here ya go.

a = game.Players:GetChildren()
m = Instance.new("Message")

function onPlayerEntered()

for i,v in pairs(a) do
    if v.Name == "CorvetteLegend" then
        m.Parent = game.Workspace
        m.Text = "CorvetteLegend has joined the game."
        wait(6)
        m:Destroy()
    else

    end
end
end)

game.Players.PlayerAdded:connect(onPlayerEntered)   
0
Thanks! CorvetteLegend 0 — 9y
0
This isn't the most efficient way. You set the a variable before the function. Sure it works when he's the first person in the server, but if someone is already in the game and he joins, the function won't respond to him because the variable was set when the first person joined. Shawnyg 4330 — 9y
Ad
Log in to vote
5
Answered by
Ekkoh 635 Moderation Voter
9 years ago

There are two issues with Slick's script. One being that a never gets updated to the new list of players, it just remembers all the players that were in the server when the script runs. Second of all, you don't need to loop through each player when a new player joins, the player that joins is passed as an argument in the PlayerAdded event. This is how I'd write it.

local Players = Game:GetService("Players")

function PlayerAdded( newPlayer )
    if newPlayer.Name == "CorvetteLegend" then
        local msg = Instance.new("Message", Workspace)
        msg.Text = "CorvetteLegend has joined the game."
        wait(6)
        msg:Destroy()
    end
end

Players.PlayerAdded:connect(PlayerAdded)
0
What about the Message's parent? Vividex 162 — 9y
0
Good catch :) Ekkoh 635 — 9y

Answer this question