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

Can someone help me with PlayerAdded?

Asked by 10 years ago

So this is my script:

01function playerAdded(player)
02    local sv = Instance.new("StringValue")
03    sv.Parent = game.Workspace
04    sv.name = "IsItBep"
05    wait(1)
06    local stringv = game.Workspace.IsItBep
07    game.Workspace.IsItBep.Value = player.Name()
08    wait(0.1)
09    if game.Workspace.IsItBep.Value == "Bep0man" then
10        local m = Instance.new("Message")
11        m.Parent = game.Workspace
12        m.Name = "ItsBep0"
13        wait(0.5)
14        local me = game.Workspace.ItsBep0
15        me.Text = "OMGGGGG GRAB YOUR MOUNTAIN DEW AND DORITOS!!! BEP0MAN IS ON THE GAME!!!!! OMOMGOMGOMGOMGGG SNOOP DOGG"
View all 24 lines...

Does anyone know why it's not working?

1
go to line 25 and add game.Players.PlayerAdded:connect(playerAdded) XToonLinkX123 580 — 10y
0
Are you calling the function? UserOnly20Characters 890 — 10y
0
Omg lol sorry forgot to call it... Bep0man 5 — 10y
1
Also in line 7 remove the Brackets from player.Name() to player.Name . There no need for a bracket to be there in the first place. UserOnly20Characters 890 — 10y

1 answer

Log in to vote
3
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
10 years ago

That code will never run in a billion years.

Functions only run when they are called. Calling a function means asking it to run by putting two parentheses after its name:

1function sayHi()
2    print("Hi")
3end
4sayHi() --This makes it run

There's nothing special about naming your function playerAdded. It's just a normal function that won't run until you tell it to.

But you don't want your function to only run once, you want it to run when a player joins. This is why we use an event. Connecting a function to an event will make it so that Roblox calls it when the event fires.

We connect the PlayerAdded event to our function:

1function sayHi()
2    print("Hi")
3end
4game.Players.PlayerAdded:connect(sayHi)

Now it will run when someone joins.



Another problem lies with line 07,

1game.Workspace.IsItBep.Value = player.Name()

Name is a property, so we shouldn't use parentheses to access it. Instead, write:

1game.Workspace.IsItBep.Value = player.Name

But we can take this out entirely just by checking the name directly:

1if player.Name == "Bep0man" then

And you have a lot of pointless variables, for example, you wrote:

1local m = Instance.new("Message")
2m.Parent = game.Workspace
3m.Name = "ItsBep0"
4wait(0.5)
5local me = game.Workspace.ItsBep0

While you could just keep using the variable m.

And,

1local sv = Instance.new("StringValue")
2sv.Parent = game.Workspace
3sv.name = "IsItBep"
4wait(1)
5local stringv = game.Workspace.IsItBep

While you could just keep using the variable sv.

0
@Perci1 I'll upvote your answer even though I stated the problem before you. :P xD UserOnly20Characters 890 — 10y
0
@Perci1, I think its funny that you bluntly say "That code will never run in a billion years.".. LOL. That just for some odd reason makes me laugh. MessorAdmin 598 — 10y
Ad

Answer this question