|
| 30 Jan 2017 06:00 PM |
local player = game.Players.LocalPlayer local stat = game.Workspace.hungervalues:findFirstChild(player) local plr = game.Players:FindFirstChild(player) function hunger() if stat.Value >1 then plr.humanoid.Health = 0 end end
How can i fix this? Thanks
r+://588066076 Looks like someone didn't eat their Wheaties this morning!™ |
|
|
| Report Abuse |
|
|
| |
|
|
| 30 Jan 2017 06:02 PM |
2
r+://588066076 Looks like someone didn't eat their Wheaties this morning!™ |
|
|
| Report Abuse |
|
|
| |
|
AxonMega
|
  |
| Joined: 29 Aug 2014 |
| Total Posts: 2403 |
|
|
| 30 Jan 2017 06:02 PM |
| Why are you calling FindFirstChild on an object? |
|
|
| Report Abuse |
|
|
|
| 30 Jan 2017 06:03 PM |
"Why are you calling FindFirstChild on an object?" because that's all you can call it on...?
|
|
|
| Report Abuse |
|
|
|
| 30 Jan 2017 06:03 PM |
im inexperienced. Also its not an object; but a folder
r+://588066076 Looks like someone didn't eat their Wheaties this morning!™ |
|
|
| Report Abuse |
|
|
|
| 30 Jan 2017 06:04 PM |
This is not a local script. Its stored in serverscriptservice
r+://588066076 Looks like someone didn't eat their Wheaties this morning!™ |
|
|
| Report Abuse |
|
|
|
| 30 Jan 2017 06:06 PM |
then you can't use LocalPlayer... :/ how is the server supposed to get a local player? it's the server and doesn't have one specific player assigned to it the only exception is play mode in studio because the client and server run in the same window
|
|
|
| Report Abuse |
|
|
|
| 30 Jan 2017 06:06 PM |
| dont use local player on a server script |
|
|
| Report Abuse |
|
|
AxonMega
|
  |
| Joined: 29 Aug 2014 |
| Total Posts: 2403 |
|
|
| 30 Jan 2017 06:06 PM |
@Unsubtleties:
No u call it on a string. Here, this link should help you and Chicken:
http://wiki.roblox.com/index.php?title=Intro_to_Scripting
|
|
|
| Report Abuse |
|
|
|
| 30 Jan 2017 06:08 PM |
axon, are you trying to be funny or are you genuinely this ignorant? you CALL FindFirstChild() on an object. you use a string as the ARGUMENT for the function.
Workspace:FindFirstChild("Part") in that example, FindFirstChild() is being called on Workspace, an object, and "Part" (the string) is the argument
here, this link should help you: http://wiki.roblox.com/index.php?title=Intro_to_Scripting
|
|
|
| Report Abuse |
|
|
AxonMega
|
  |
| Joined: 29 Aug 2014 |
| Total Posts: 2403 |
|
|
| 30 Jan 2017 06:12 PM |
Okay, I'm going to you how this works. In this code:
part:FindFirstChild("Value")
"part" refers to the object which you are indexing a method of. The string "Value", the argument, is what you are calling the function on. You are partially correct in that when using ":" instead of "." to index a method, it is called with the object as the first argument and all of the other arguments you put in following.
Does this make sense? |
|
|
| Report Abuse |
|
|
|
| 30 Jan 2017 06:13 PM |
Ok now i am just confuesed
r+://588066076 Looks like someone didn't eat their Wheaties this morning!™ |
|
|
| Report Abuse |
|
|
|
| 30 Jan 2017 06:16 PM |
there's only one part that makes sense, the rest seems like you're talking out of your ass
just because you're supplying an argument to a function/method does NOT mean you're calling the function on the argument. that's one of the dumbest things i've ever heard.
what about calling a function that takes no arguments? does that mean you're calling it on nil? or one that takes multiple arguments, does that mean you're calling it on every single argument?
...what?
|
|
|
| Report Abuse |
|
|
|
| 30 Jan 2017 06:18 PM |
when you replied with "No u call it on a string." you really should be saying you call it with a string (implying you use a string as an argument)
saying "call it on a string" pretty much implies the following: "String":FindFirstChild("Part")
|
|
|
| Report Abuse |
|
|
AxonMega
|
  |
| Joined: 29 Aug 2014 |
| Total Posts: 2403 |
|
|
| 30 Jan 2017 06:29 PM |
All of what I said could have been easily understood by an advanced scripter. I will try to explain it to you one more time out of generosity:
Objects are like tables with their own individual identities. In the code:
part:FindFirstChild("Value")
you are indexing the object "part" at the index "FindFirstChild", and then calling the item this returns as a function with the argument "Value". Functions stored inside objects as such are known as "methods". When indexing a method with the ":" operator as opposed to "." or "[]", all of the arguments you call the method with are shifted to the right one space, and the object you index the method becomes the first argument. Do you understand? |
|
|
| Report Abuse |
|
|
|
| 30 Jan 2017 06:37 PM |
I know how the FindFirstChild() function works.
anyway, with that explanation you decided to write me for no reason, where's the part where calling FindFirstChild() would be on a string?
you're not calling it on a string, you're calling it as a method of the Instance class.
|
|
|
| Report Abuse |
|
|
|
| 30 Jan 2017 06:38 PM |
Unsubtleties is completely correct. Regardless of how you intended it, you do not call FindFirstChild *on* a string. Methods are no different from functions, other than the syntax sugar for calling them and passing the *object* they're being called on as the first argument (represented by the self variable, if the function was created as a method as well). In other words, Object:FindFirstChild("Name") would be no different than Object.FindFirstChild(Object, "Name").
|
|
|
| Report Abuse |
|
|
|
| 30 Jan 2017 06:38 PM |
How about you solve it for me and i find out who is right. This is really confusing having 2 people saying different things.
r+://588066076 Looks like someone didn't eat their Wheaties this morning!™ |
|
|
| Report Abuse |
|
|
AxonMega
|
  |
| Joined: 29 Aug 2014 |
| Total Posts: 2403 |
|
|
| 30 Jan 2017 06:39 PM |
| You have a long ways to go. It'll all make sense one day. |
|
|
| Report Abuse |
|
|
|
| 30 Jan 2017 06:40 PM |
it would make sense. If 2 people did not have 2 different views.
r+://588066076 Looks like someone didn't eat their Wheaties this morning!™ |
|
|
| Report Abuse |
|
|
AxonMega
|
  |
| Joined: 29 Aug 2014 |
| Total Posts: 2403 |
|
|
| 30 Jan 2017 06:42 PM |
@ScriptGuider
That's what I tried to tell him in my first explanation. |
|
|
| Report Abuse |
|
|
|
| 30 Jan 2017 06:45 PM |
okay sorry OP
local player = game.Players.LocalPlayer -- first of all the server doesn't have its own LocalPlayer, you need another way to reference the player
local stat = game.Workspace.hungervalues:findFirstChild(player) -- this already won't work since you can't use LocalPlayer on the server
local plr = game.Players:FindFirstChild(player) -- neither will this
function hunger() if stat.Value >1 then plr.humanoid.Health = 0 -- this should be plr.Character.Humanoid.Health = 0; Humanoid exists inside the player's character, not the player itself -- Character is a property of Player, not a descendant, so therefore you can't call FindFirstChild() on it end end
along with using LocalPlayer on the server your other issue is trying to call FindFirstChild() with an object as the argument; you're supposed to use a string
|
|
|
| Report Abuse |
|
|
|
| 30 Jan 2017 06:46 PM |
"That's what I tried to tell him in my first explanation."
really? you had a really interesting way of doing so...
"The string "Value", the argument, is what you are calling the function on."
|
|
|
| Report Abuse |
|
|