Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Can someone help me with PlayerAdded?

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?

4 comments

1

go to line 25 and add game.Players.PlayerAdded:connect(playerAdded)

0

Are you calling the function?

0

Omg lol sorry forgot to call it...

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.

1 answer

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.

2 comments

0

@Perci1 I'll upvote your answer even though I stated the problem before you. :P xD

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.