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 9 years ago

So this is my script:

function playerAdded(player)
    local sv = Instance.new("StringValue")
    sv.Parent = game.Workspace
    sv.name = "IsItBep"
    wait(1)
    local stringv = game.Workspace.IsItBep
    game.Workspace.IsItBep.Value = player.Name()
    wait(0.1)
    if game.Workspace.IsItBep.Value == "Bep0man" then
        local m = Instance.new("Message")
        m.Parent = game.Workspace
        m.Name = "ItsBep0"
        wait(0.5)
        local me = game.Workspace.ItsBep0
        me.Text = "OMGGGGG GRAB YOUR MOUNTAIN DEW AND DORITOS!!! BEP0MAN IS ON THE GAME!!!!! OMOMGOMGOMGOMGGG SNOOP DOGG"
        wait(4)
        me.Text = "NO RLLY ITS SO EPIK LIKE 9000!!! (HEAD EXPLODES FORM EPIKNESS)"
        wait(4)
        me:Destroy()
        game.Workspace.IsItBep:Destroy()
    else
        game.Workspace.IsItBep:Destroy()
    end
end

Does anyone know why it's not working?

1
go to line 25 and add game.Players.PlayerAdded:connect(playerAdded) XToonLinkX123 580 — 9y
0
Are you calling the function? UserOnly20Characters 890 — 9y
0
Omg lol sorry forgot to call it... Bep0man 5 — 9y
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 — 9y

1 answer

Log in to vote
3
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 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:

function sayHi()
    print("Hi")
end
sayHi() --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:

function sayHi()
    print("Hi")
end
game.Players.PlayerAdded:connect(sayHi)

Now it will run when someone joins.



Another problem lies with line 07,

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

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

game.Workspace.IsItBep.Value = player.Name

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

if player.Name == "Bep0man" then

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

 local m = Instance.new("Message")
m.Parent = game.Workspace
m.Name = "ItsBep0"
wait(0.5)
local me = game.Workspace.ItsBep0

While you could just keep using the variable m.

And,

local sv = Instance.new("StringValue")
sv.Parent = game.Workspace
sv.name = "IsItBep"
wait(1)
local 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 — 9y
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 — 9y
Ad

Answer this question