|
| 11 Mar 2013 03:45 PM |
function onButton1Down(mouse) local target = mouse.Target local tarhunger = target.Hunger.Value local tarthirst = target.Thirst.Value local tarstamina = target.Stamina.Value local tarhealth = target.Health.Value
local player = script.Parent.Parent.Parent local playerStat = player.PlayerGui.StatGUI local playerhunger = playerStat.Hunger.Value local playerthirst = playerStat.Thirst.Value local playerstamina = playerStat.Stamina.Value print(target)
if target.Locked == false then if target.Food.Value == true then playerhunger = playerhunger + tarhunger playerthirst = playerthirst + tarthirst playerstamina = playerstamina + tarstamina
target:remove() end end end
function onSelected(mouse) mouse.Button1Down:connect(onButton1Down) end
script.Parent.Selected:connect(onSelected)
This a script for a Eat Tool. When I click an apple I get an error in the output: 16:42:00.867 - Players.Player1.Backpack.Eat.Script:2: attempt to index local 'mouse' (a nil value)
I'm not very experianced with mouse and keyboard clicking and binding so I'm not sure why my script is erroring. Any help is greatly apreciated. Sorry if my spelling is a bit bad.
|
|
|
| Report Abuse |
|
|
|
| 11 Mar 2013 03:47 PM |
I assume it is because it is confusing Button1Down as a function and as a variable Just change the name of the function first and see if that works
mouse.Button1Down:connect(Changeme)
function Changeme(mouse) |
|
|
| Report Abuse |
|
|
|
| 11 Mar 2013 03:49 PM |
Change:
function onButton1Down(mouse)
To:
function onButton1Down()
¤ ¤ † K M <( •д• )> X D † ¤ ¤
|
|
|
| Report Abuse |
|
|
|
| 11 Mar 2013 03:57 PM |
Ahhhh KnightmareXD is right... Didn't catch that he already called the mouse on equip. |
|
|
| Report Abuse |
|
|
|
| 11 Mar 2013 03:58 PM |
| I tried both. I got the same output. |
|
|
| Report Abuse |
|
|
|
| 11 Mar 2013 04:00 PM |
Just do what Cat suggested, something like:
script.Parent.Selected:connect(function( mouse ) mouse.Button1Down:connect(function( ) local target = mouse.Target local tarhunger = target.Hunger.Value local tarthirst = target.Thirst.Value local tarstamina = target.Stamina.Value local tarhealth = target.Health.Value local player = script.Parent.Parent.Parent local playerStat = player.PlayerGui.StatGUI local playerhunger = playerStat.Hunger.Value local playerthirst = playerStat.Thirst.Value local playerstamina = playerStat.Stamina.Value print(target) if target.Locked == false then if target.Food.Value == true then playerhunger = playerhunger + tarhunger playerthirst = playerthirst + tarthirst playerstamina = playerstamina + tarstamina target:remove() end end end ) end )
¤ ¤ † K M <( •д• )> X D † ¤ ¤ |
|
|
| Report Abuse |
|
|
|
| 11 Mar 2013 04:05 PM |
| The errors are gone and when I click apple it prints Apple and then removes Apple. However, when I click and it's removed it doesn't add the stats to my stat bar. |
|
|
| Report Abuse |
|
|
|
| 11 Mar 2013 04:08 PM |
If you put the properties in the variables, you can't change them using that variable:
script.Parent.Selected:connect(function( mouse ) mouse.Button1Down:connect(function( ) local target = mouse.Target local tarhunger = target.Hunger local tarthirst = target.Thirst local tarstamina = target.Stamina local tarhealth = target.Health local player = script.Parent.Parent.Parent local playerStat = player.PlayerGui.StatGUI local playerhunger = playerStat.Hunger local playerthirst = playerStat.Thirst local playerstamina = playerStat.Stamina print(target) if target.Locked == false then if target.Food.Value == true then playerhunger.Value = playerhunger.Value + tarhunger.Value playerthirst.Value = playerthirst.Value + tarthirst.Value playerstamina.Value = playerstamina.Value + tarstamina.Value target:remove() end end end ) end )
¤ ¤ † K M <( •д• )> X D † ¤ ¤ |
|
|
| Report Abuse |
|
|
|
| 11 Mar 2013 04:53 PM |
Thanks. After learning that you can't have varibles where properties are included I went back and fixed some other bugs in the stat scripts. Now that all works fine. I'm also having some trouble with a sleep button though. Here's the script:
local asleep = false local button = script.Parent local stamina = script.Parent.Parent.Parent.Stamina.Value local player = script.Parent.Parent.Parent.Parent.Parent wait(3) local char = player.Character
function activate() asleep = true end
while asleep == true do char.Humanoid.Sit = true wait(1) stamina = stamina + 2 if char.Humanoid.Sit == false then asleep = false end end
button.MouseButton1Down:connect(activate)
print(asleep) |
|
|
| Report Abuse |
|
|
|
| 11 Mar 2013 04:57 PM |
the problem would be that when it runs the while loop first asleep is false so it doesn't run.
local asleep = false local button = script.Parent local stamina = script.Parent.Parent.Parent.Stamina.Value local player = script.Parent.Parent.Parent.Parent.Parent wait(3) local char = player.Character
function activate() asleep = true end
button.MouseButton1Down:connect(activate)
repeat wait() until asleep
while asleep == true do char.Humanoid.Sit = true wait(1) stamina = stamina + 2 if char.Humanoid.Sit == false then asleep = false end end
|
|
|
| Report Abuse |
|
|
|
| 11 Mar 2013 05:02 PM |
| Tried it. Still won't work. I thing something is going wrong when I click it. When a click nothing happens at all. No errors and no stat changes. |
|
|
| Report Abuse |
|
|
|
| 11 Mar 2013 05:09 PM |
see what this prints in output
local asleep = false local button = script.Parent local stamina = script.Parent.Parent.Parent.Stamina.Value local player = script.Parent.Parent.Parent.Parent.Parent wait(3) local char = player.Character
function activate() asleep = true print"Sleeping" end
button.MouseButton1Down:connect(activate)
repeat wait() until asleep print"Passed Test" while asleep == true do print"In while loop" char.Humanoid.Sit = true wait(1) stamina = stamina + 2 if char.Humanoid.Sit == false then print"Person woke up" asleep = false end end |
|
|
| Report Abuse |
|
|
|
| 11 Mar 2013 05:10 PM |
| Nothing at all printed. I don't think it's activating when I click. |
|
|
| Report Abuse |
|
|
|
| 11 Mar 2013 05:13 PM |
see if there is any output this time...also i fixed it so it will actually give stamina...if you put .Value in the variable it will just change the variable not the stamina object.
local asleep = false local button = script.Parent local stamina = script.Parent.Parent.Parent.Stamina local player = script.Parent.Parent.Parent.Parent.Parent repeat wait() until player.Character local char = player.Character print"Variables Loaded"
function activate() asleep = true print"Sleeping" end
button.MouseButton1Down:connect(activate)
repeat wait() until asleep print"Passed Test" while asleep == true do print"In while loop" char.Humanoid.Sit = true wait(1) stamina.Value = stamina.Value + 2 if char.Humanoid.Sit == false then print"Person woke up" asleep = false end end |
|
|
| Report Abuse |
|
|
ScriptOn
|
  |
| Joined: 22 Aug 2010 |
| Total Posts: 10885 |
|
| |
|
|
| 11 Mar 2013 05:19 PM |
| All that printed was Varibles Loaded. Thank you for fixing varibles. I thought I fixed it but with all the scripts I've tried it would be easy for it to revert back by accident. |
|
|
| Report Abuse |
|
|
| |
|
|
| 11 Mar 2013 05:32 PM |
| Do I maybe need to use the function GetMouse() ? |
|
|
| Report Abuse |
|
|
|
| 11 Mar 2013 05:45 PM |
| I just noticed something, when I move my mouse over the button it doesn't light up like the other button I have. I didn't notice this before because I thought it was normal. But now I relize it's not lighting up. What could be the problem? |
|
|
| Report Abuse |
|
|