oYoxo
|
  |
| Joined: 18 Dec 2014 |
| Total Posts: 14 |
|
|
| 23 Dec 2014 07:30 PM |
I am brand new to all of this but I am trying to learn as I go. But I am stuck and I'm not sure how to ask for help. In my program, I have a bush with grapes on it. When you click a grape it disappears for a while, and then reappears. What I want it to do is also add some value to the "Food" stat that I made in the leaderboard. I think I am close but I know I am missing something. My problem is, I have no idea what to ask Google to get the answer I need. Can anyone help? (my problem is on line 8, dealing with locating the player who clicked the grape)
Here is my code.....
grape = script.Parent value = script.Parent.FoodValue
function respawn() if grape.Transparency == 0 then -- if grape is visible grape.Transparency = 1 -- make grape invisible grape.CanCollide = false -- make grape unclickable player = game.Players:FindFirstChild() -- ?????????? player.leaderstats.Food.Value = player.leaderstats.Food.Value + value -- add grape value to player food value wait(5) -- wait X seconds grape.Transparency = 0 -- respawn grape end end
grape.ClickDetector.MouseClick:connect(respawn)
Here is my error message 19:26:20.674 - Argument 1 missing or nil 19:26:20.675 - Script 'Workspace.Grape Bush.Part.Script', Line 8 19:26:20.675 - Stack End 19:26:20.675 - Disconnected event because of exception
Thanks in advance. |
|
|
| Report Abuse |
|
|
|
| 23 Dec 2014 07:32 PM |
the .MouseClick event gives you the player who clicked as an argument so...
function respawn(playerWhoClicked) |
|
|
| Report Abuse |
|
|
Marzlyn
|
  |
| Joined: 15 Jun 2014 |
| Total Posts: 4431 |
|
|
| 23 Dec 2014 07:37 PM |
For this my friend you need something called arguments
When the player touched it, the event can call an argument, that argument of course will be the player
let's slowly understand this
function touch(PART) print("This thing called "..PART.name) end script.Parent.Touched:connect(touch)
What the upper script does is, when the touched event is triggered, it calls the function (touch) and if there are any argument variables called like we called "PART" , then we basically add the name or the value of the player whom touched to the value of PART
so if a Part touched that other Part
the output would be
This thing called Part
in our case
grape = script.Parent value = script.Parent.FoodValue
function respawn(plr)--Here you add who clicked it if grape.Transparency == 0 then -- if grape is visible grape.Transparency = 1 -- make grape invisible grape.CanCollide = false -- make grape unclickable player = game.Players:FindFirstChild(plr.Name) -- ?????????? player.leaderstats.Food.Value = player.leaderstats.Food.Value + value -- add grape value to player food value wait(5) -- wait X seconds grape.Transparency = 0 -- respawn grape end end
grape.ClickDetector.MouseClick:connect(respawn)
|
|
|
| Report Abuse |
|
|
oYoxo
|
  |
| Joined: 18 Dec 2014 |
| Total Posts: 14 |
|
|
| 23 Dec 2014 07:56 PM |
Awesome thanks. Not only did those changes work, but I think I understand it now! And that actually answers a few of the questions I got stuck in in other places. But, now I am getting an error on line 9...
19:48:54.374 - Workspace.Grape Bush.Part.Script:9: attempt to perform arithmetic on global 'value' (a userdata value)
What have I done wrong here? (I am pretty sure I have all the correct IntValues in the correct places and named correctly.) |
|
|
| Report Abuse |
|
|
oYoxo
|
  |
| Joined: 18 Dec 2014 |
| Total Posts: 14 |
|
|
| 23 Dec 2014 08:08 PM |
| Nevermind, I figured it out. But thanks a lot for the lesson! =) |
|
|
| Report Abuse |
|
|
oYoxo
|
  |
| Joined: 18 Dec 2014 |
| Total Posts: 14 |
|
|
| 23 Dec 2014 08:27 PM |
Okay, I lied. I found the issue, but I can not figure out how to fix it. My problem is that the IntValue labeled "FoodValue" is not keeping its value (of 50) that I set it to in the Explorer window. Am I required to set its value via script?
Heres the important info...
value = script.Parent.FoodValue -- (I have an IntValue inside the part, labeled "FoodValue" with a value of 50) If I understand this correctly, I am setting my variable 'value' equal to whatever the FoodValue is set to, which should be 50.
player.leaderstats.Food.Value = player.leaderstats.Food.Value + value -- this works, but it wants to add a value of 0 to my leaderstats.Food.Value instead of the 50 that I set it to.
If i rewrite it to say... player.leaderstats.Food.Value = player.leaderstats.Food.Value + 50 ...it works just fine
I could also just rewrite the 'value' variable to say... value = 50 .. and just do it like that, and delete the IntValue inside the Part, but I sort of want to understand why this isnt working.
I hope I made sense and thanks to anyone who can offer any info. =) |
|
|
| Report Abuse |
|
|
iceman72
|
  |
| Joined: 08 Jun 2008 |
| Total Posts: 786 |
|
|
| 23 Dec 2014 09:00 PM |
| I didn't read everything on this post but I think I found your problem. FoodValue is suposed to be Food.Value. Your intValue should be named just Food. What Food.Value dose is it gets the value saved in the intValue! If you take a look at an intValue in the properties tab you will see the number is in a field called Value. Hope this helps! |
|
|
| Report Abuse |
|
|
oYoxo
|
  |
| Joined: 18 Dec 2014 |
| Total Posts: 14 |
|
|
| 23 Dec 2014 09:05 PM |
| Ohhhhhh okay. Yep, I believe that will fix my problem. Thanks a bunch. |
|
|
| Report Abuse |
|
|