generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Using CharacterAdded in a normal function?

Previous Thread :: Next Thread 
crystal12752 is not online. crystal12752
Joined: 06 May 2011
Total Posts: 407
10 Apr 2015 09:24 AM
Does anyone know how to use the CharacterAdded event in a normal function, and not an anonymous one?
I don't know any other way to track a player's character in the workspace upon joining the game besides using this:
game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function(character)
end)
end)

Any other ways I could do it?


I am an owl.
Report Abuse
NovusTheory is not online. NovusTheory
Joined: 14 Oct 2009
Total Posts: 4532
10 Apr 2015 09:26 AM
player.CharacterAdded:connect(characterAdded())

Then have a function named that


Total Posts: 404 ---------- Not Found
Report Abuse
crystal12752 is not online. crystal12752
Joined: 06 May 2011
Total Posts: 407
10 Apr 2015 09:26 AM
Would the server automatically know what "player" is?
I thought you had to like set "player" to some variable.


I am an owl.
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
10 Apr 2015 09:28 AM
You do. You can use PlayerAdded.
Report Abuse
crystal12752 is not online. crystal12752
Joined: 06 May 2011
Total Posts: 407
10 Apr 2015 09:28 AM
I put it into studio mode. This is what it looks like:


function characterAdded() <----I think I did that right.

end

player.CharacterAdded:connect(characterAdded())

And at the player, underlined in blue, it says, "Unknown global 'player'"


I am an owl.
Report Abuse
crystal12752 is not online. crystal12752
Joined: 06 May 2011
Total Posts: 407
10 Apr 2015 09:29 AM
Sorry guys, beginner at scripting here.
I don't know everything about functions, yet. :D


I am an owl.
Report Abuse
NovusTheory is not online. NovusTheory
Joined: 14 Oct 2009
Total Posts: 4532
10 Apr 2015 09:30 AM
game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:connect(characterAdded())
end)
end)



Total Posts: 404 ---------- Not Found
Report Abuse
NovusTheory is not online. NovusTheory
Joined: 14 Oct 2009
Total Posts: 4532
10 Apr 2015 09:31 AM
woops forgot to remove an end)


Total Posts: 404 ---------- Not Found
Report Abuse
crystal12752 is not online. crystal12752
Joined: 06 May 2011
Total Posts: 407
10 Apr 2015 09:33 AM
Is that a named or anonymous function? :o



I am an owl.
Report Abuse
NovusTheory is not online. NovusTheory
Joined: 14 Oct 2009
Total Posts: 4532
10 Apr 2015 09:34 AM
I just fixed your player variable problem. It's not anonymous


Total Posts: 404 ---------- Not Found
Report Abuse
crystal12752 is not online. crystal12752
Joined: 06 May 2011
Total Posts: 407
10 Apr 2015 09:35 AM
Ah.
But it says that the "characterAdded" in the parentheses is an unknown global variable :o


I am an owl.
Report Abuse
Seattlantis is not online. Seattlantis
Joined: 24 Jul 2013
Total Posts: 5560
10 Apr 2015 09:35 AM
function PlayerAdded(player)
function CharacterAdded(character)
--stuff here
player.CharacterAdded:connect(CharacterAdded)
game.Players.PlayerAdded:connect(PlayerAdded)
Report Abuse
Seattlantis is not online. Seattlantis
Joined: 24 Jul 2013
Total Posts: 5560
10 Apr 2015 09:36 AM
forgot the ends on my post, you get the gist though
Report Abuse
crystal12752 is not online. crystal12752
Joined: 06 May 2011
Total Posts: 407
10 Apr 2015 09:37 AM
:o I think you did it.
Hooray! :D


I am an owl.
Report Abuse
crystal12752 is not online. crystal12752
Joined: 06 May 2011
Total Posts: 407
10 Apr 2015 09:38 AM
Oh and, does C0 and C1 still exist in a weld?
It confuses me and there's only Part0 and Part1 in the weld's properties.



I am an owl.
Report Abuse
Seattlantis is not online. Seattlantis
Joined: 24 Jul 2013
Total Posts: 5560
10 Apr 2015 09:39 AM
actually no, this would be the working script


repeat wait() until game.Players.LocalPlayer

function PlayerAdded(player)
function CharacterAdded(character)
print("Player joined")
end
end
game.Players.LocalPlayer.CharacterAdded:connect(CharacterAdded)
game.Players.PlayerAdded:connect(PlayerAdded)

but it errors: Attempt to connect failed: Passed value is not a function
Report Abuse
crystal12752 is not online. crystal12752
Joined: 06 May 2011
Total Posts: 407
10 Apr 2015 09:44 AM
Hmm :o
I never know what it means when it says the passed value isn't a function. Lol.


I am an owl.
Report Abuse
crystal12752 is not online. crystal12752
Joined: 06 May 2011
Total Posts: 407
10 Apr 2015 09:59 AM
Can anyone help me with one that can work?
I don't think LocalPlayer works anymore, not sure. I tried the one the wiki gave me and it didn't work in a local script.


I am an owl.
Report Abuse
NovusTheory is not online. NovusTheory
Joined: 14 Oct 2009
Total Posts: 4532
10 Apr 2015 10:20 AM
Just to say

@Seat

Why are you you using PlayerAdded in a LocalScript?


Total Posts: 404 ---------- Not Found
Report Abuse
crystal12752 is not online. crystal12752
Joined: 06 May 2011
Total Posts: 407
10 Apr 2015 10:30 AM
I don't think he recommended it to me, but i read the wiki, which said it works in local scripts and stuff.
Report Abuse
NovusTheory is not online. NovusTheory
Joined: 14 Oct 2009
Total Posts: 4532
10 Apr 2015 10:31 AM
Where did you see it works for LocalScripts?

"This event does not fire for LocalScripts"


Total Posts: 404 ---------- Not Found
Report Abuse
crystal12752 is not online. crystal12752
Joined: 06 May 2011
Total Posts: 407
10 Apr 2015 10:46 AM
It said on the wiki when I looked it up in the studio.
here's what it says:

Value Type: Object
Description: The Player that the LocalScript is running for.
Example
This gets the Player the LocalScript is running in. This must be in a LocalScript to work correctly throughout servers.

local player = game.Players.LocalPlayer
print(player:GetFullName())


link:
http://wiki.roblox.com/index.php?title=API:Class/Players/LocalPlayer

Wait am I allowed to post wiki links? :o


I am an owl.
Report Abuse
NovusTheory is not online. NovusTheory
Joined: 14 Oct 2009
Total Posts: 4532
10 Apr 2015 10:47 AM
Oh no, I was talking about PlayerAdded


Total Posts: 404 ---------- Not Found
Report Abuse
crystal12752 is not online. crystal12752
Joined: 06 May 2011
Total Posts: 407
10 Apr 2015 10:51 AM
Ohhh.
I thought you were talking about the LocalPlayer or something.
XD
But anyways,
I tried these scripts, but none worked.
game.Players.PlayerAdded:connect(function(player)
player.CharacterAdded:connect(characterAdded())
end)
end) <--- yours looks a lot like the one I used, except mine is anonymous. The studio says that the "(characterAdded())" part is an unknown global 'characterAdded' or whatever.
What does it mean? :o


I am an owl.
Report Abuse
crystal12752 is not online. crystal12752
Joined: 06 May 2011
Total Posts: 407
10 Apr 2015 11:03 AM
Bump? :o


I am an owl.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image