|
| 10 Mar 2012 07:44 PM |
| I'm trying to create classes in a game, and need to get the player in order to give them tools. I tried using the overall model and the humanoid, but it keeps saying that "getPlayer is not a valid function of (model/humanoid/etc.) What should I reference to retrieve the player? |
|
|
| Report Abuse |
|
|
|
| 10 Mar 2012 07:52 PM |
Oh, I forgot to post the specific code:
function touched(hit) character = hit.Parent:FindFirstChild("Humanoid") player = character:getPlayer() game.Lighting.item.clone().Parent = player.Backpack end |
|
|
| Report Abuse |
|
|
|
| 10 Mar 2012 07:56 PM |
Try GetPlayerFromCharecter instead of getPlayer
+-Fishy |
|
|
| Report Abuse |
|
|
|
| 10 Mar 2012 08:02 PM |
"getPlayerFromCharacter is not a valid member of Humanoid" or the alternative getPlayerFromCharacter(character) "attempt to call global getPlayerFromCharacter a nil value
Also tried making it "local player = ___" |
|
|
| Report Abuse |
|
|
|
| 10 Mar 2012 08:08 PM |
Are you making it like, that people touch a button and they get tools?
|
|
|
| Report Abuse |
|
|
|
| 10 Mar 2012 08:10 PM |
Hmmmm I don't know. I've never seen someone try to get a player from a character, and then give them tools this way before...
+-Fishy |
|
|
| Report Abuse |
|
|
|
| 10 Mar 2012 08:15 PM |
If it works with buttons:
x = button:findFirstChild("Humanoid")
x.Parent.Name --The parent of the Humanoid is the character model, which is --the player's name, so we take that name. player =game.Players:findFirstChild(x) --searches the Player list for X, if Im correct, im not 100% sure about the (x) thing, but it's worth a shot.
|
|
|
| Report Abuse |
|
|
|
| 10 Mar 2012 08:18 PM |
@OwningDutchMan, Yes.
@FisherPenguin, I had remembered seeing it somewhere before.
--- Anyway, I decided to take a look at SFOTHIV, knowing Telamon used something similar to create the jetboots (which are stored in lighting).
I did some script integration, and got it to work. Finished product, in case anyone would like to see (sorry for any formatting errors due to ROBLOX's forum system being inadequate): ( -- Project: Class Designation -- Creator: Donald -- Date: 2012-3-10
-- The purpose of this script is to create a way to assign classes based on a button being walked on. -- The following script is an example of one of those classes, the warrior.
-- Variable Declaration and Initialization Phase
-- These variables are the values being assigned to the character. -- They are listed at the start in order to allow it to be easily changed later.
wlkspd = 15 -- This is the character's new walkspeed.
hp = 120 -- This is the character's new health/maxhealth.
--The following will become the items the player recieves in their backpack. --Later on, it might move into the starterpack instead. item1 = game.Lighting.SwordAndShield item2 = game.Lighting.Healpack item3 = game.Lighting.Healpack
-- Function Phase
-- This function gets a list of the players and then finds which one matches with the humanoid. -- The function fires when referrenced by the "touched" function. function getPlayer(humanoid) local players = game.Players:getChildren() for i = 1, #players do if players[i].Character.Humanoid == humanoid then return players[i] end end return nil end
-- This function fires when the script's parent is touched. -- It assigns a new walkspeed and health to the player, in addition to giving out proper weapons. -- As the game features multiple classes, it tries to balance out several factors. function touched(hit)
local human = hit.Parent:findFirstChild("Humanoid") if (human == nil) then return end
local player = getPlayer(human) -- Fires the getPlayer function
if (player == nil) then return end human.WalkSpeed = wlkspd -- Assigns a new walkspeed. human.MaxHealth = hp -- Assigns a new health total human.Health = human.MaxHealth item1:clone().Parent = player.Backpack -- Puts into backpack. item2:clone().Parent = player.Backpack -- Puts into backpack. item3:clone().Parent = player.Backpack -- Puts into backpack. end script.Parent.Touched:connect(touched) -- Not using anynomous functions for clarity to readers. -- Therefore, the connector line must be used. ) |
|
|
| Report Abuse |
|
|
|
| 10 Mar 2012 08:46 PM |
Erm, I seem to be having problems adding debounce into the script. It doesn't error, but it still fires more than once. Could somebody help me with that? I'm removing all the comments to make it easier to read. Also getting rid of parts that definitely aren't intervening with the problem. ( local debounce = false
function getPlayer(humanoid) local players = game.Players:getChildren() for i = 1, #players do if players[i].Character.Humanoid == humanoid then return players[i] end end return nil end
function touched(hit) if not debounce then debounce = true local human = hit.Parent:findFirstChild("Humanoid") if (human == nil) then return end
local player = getPlayer(human)
if (player == nil) then return end human.WalkSpeed = wlkspd item1:clone().Parent = player.Backpack -- Puts into backpack. debounce = false wait(2) end end script.Parent.Touched:connect(touched) |
|
|
| Report Abuse |
|
|
Levidoo6
|
  |
| Joined: 22 Aug 2009 |
| Total Posts: 1526 |
|
|
| 10 Mar 2012 09:55 PM |
| Hm, well let me think? Are you using tools in this script? Are you using uh I forgot the name? Anyway the ther kind of script? And another thing to make clear. Are you making a weapon or what? |
|
|
| Report Abuse |
|
|
|
| 10 Mar 2012 10:09 PM |
In the player declaration, it should be:
local player = game.Players:GetPlayerFromCharacter(human.Parent)
Another way would be this:
local player = game.Players:FindFirstChild(human.Parent.Name) |
|
|
| Report Abuse |
|
|
|
| 10 Mar 2012 10:25 PM |
^ WIN
~would you like some butter with your late toast? |
|
|
| Report Abuse |
|
|
|
| 10 Mar 2012 10:26 PM |
Goodness gracious. Simple errors people. Stop overlooking them. I'm actually surprised I'm the first person to find this... -.-
The problem is on this line:
character = hit.Parent:findFirstChild("Humanoid")
Your telling the computer that the character's humanoid is the character. Change to:
if hit.Parent:findFirstChild("Humanoid") then character = hit.Parent end |
|
|
| Report Abuse |
|
|
|
| 10 Mar 2012 10:27 PM |
bl5, are you trying to troll? if so it's not working >.>
~would you like some butter with your late toast? |
|
|
| Report Abuse |
|
|
|
| 10 Mar 2012 10:29 PM |
| No I'm not actually I just find it funny nobody found this error. |
|
|
| Report Abuse |
|
|
|
| 10 Mar 2012 10:32 PM |
well find it funny that you don't know the Lua syntax and found something that wasn't an error, just paraphasing some code. eg. for english:
your 'error': "I buy pizza on fridays."
your 'fix': "On fridays I buy pizza"
~would you like some butter with your late toast? |
|
|
| Report Abuse |
|
|
|
| 10 Mar 2012 10:34 PM |
@bl5,
I said at the start that I had already used Humanoid and the model. The scripts I posted just happened to be iterations with the humanoid. Anyway, as posted a bit ago, the problem has been solved, so thank you for your attempt to help. |
|
|
| Report Abuse |
|
|
|
| 10 Mar 2012 10:35 PM |
thejdude, pointed out the error :P
~would you like some butter with your late toast? |
|
|
| Report Abuse |
|
|
|
| 10 Mar 2012 10:36 PM |
You don't know what your talking about. What he did is he set the 'character' variable to the character humanoid. Not the player itself. That is why the output said something like:
getPlayerFromCharacter is not a valid member of Humanoid.
What are you trying to prove anyway. :P |
|
|
| Report Abuse |
|
|
|
| 10 Mar 2012 10:44 PM |
@bl,
It was also saying 'not a valid member of model". The script iterations I posted were just different. I probably typed something wrong. Don't worry about it. |
|
|
| Report Abuse |
|
|
|
| 10 Mar 2012 10:52 PM |
bl5, he was checking to see if a Humanoid object was in the model of the brick touching it. because that's the simplest way to check if a player had touched the brick...
~would you like some butter with your late toast? |
|
|
| Report Abuse |
|
|
Levidoo6
|
  |
| Joined: 22 Aug 2009 |
| Total Posts: 1526 |
|
|
| 11 Mar 2012 12:33 PM |
Player above do you know how to inter the hummanoid? I do. game.Workspace.Players.Hummanoid.Jump = true
I thought about other sentences to make this script sentence! |
|
|
| Report Abuse |
|
|
Levidoo6
|
  |
| Joined: 22 Aug 2009 |
| Total Posts: 1526 |
|
|
| 11 Mar 2012 12:34 PM |
| Also did you use HopperBin in the script? You need to put that in in the tool I think? I don't exactly know. |
|
|
| Report Abuse |
|
|