96mg
|
  |
| Joined: 15 May 2017 |
| Total Posts: 775 |
|
|
| 25 Jul 2017 02:01 PM |
Since it's only read, is there a way to bypass this and get the name?
wunt s0m3 b0rk? |
|
|
| Report Abuse |
|
|
|
| 25 Jul 2017 02:03 PM |
| Create a StringValue in Workspace and set it to that? I'm not entirely sure what you're asking. |
|
|
| Report Abuse |
|
|
96mg
|
  |
| Joined: 15 May 2017 |
| Total Posts: 775 |
|
|
| 25 Jul 2017 02:07 PM |
When I try to call Mouse.Target.Name
14:54:57.648 - Players.96mg.Backpack.Pickup.LocalScript:7: attempt to index field 'Target' (a nil value)
wunt s0m3 b0rk? |
|
|
| Report Abuse |
|
|
XBLAX
|
  |
| Joined: 06 Apr 2012 |
| Total Posts: 82 |
|
| |
|
96mg
|
  |
| Joined: 15 May 2017 |
| Total Posts: 775 |
|
|
| 25 Jul 2017 02:10 PM |
Hit uses CFrame, Im trying to get the Targets Name
wunt s0m3 b0rk? |
|
|
| Report Abuse |
|
|
|
| 25 Jul 2017 02:10 PM |
You get that error when the mouse isnt pointing at anything(any parts) and you try to read the target
you can read Mouse.Target.Name just fine.
A programming LMaD'er |
|
|
| Report Abuse |
|
|
INTELZEK
|
  |
| Joined: 29 Sep 2012 |
| Total Posts: 362 |
|
|
| 25 Jul 2017 02:11 PM |
I think you might be calling it when the mouse isn't over anything. So maybe, before it, put a if mouse.Target ~= nil then.
|
|
|
| Report Abuse |
|
|
96mg
|
  |
| Joined: 15 May 2017 |
| Total Posts: 775 |
|
|
| 25 Jul 2017 02:11 PM |
Here's the script
plr = game.Players.LocalPlayer mouse = plr:GetMouse() c = game.Workspace.GameDrops Resources = {"Apple","Banana","Coconut","Glass Vial","Vial of Water"}
mouse.Button1Up:Connect(function(hit) if mouse.Hit.Name == Resources then print(plr.Name.."Has Clicked a Resource") elseif mouse.Hit.Name ~= Resources then print("This is not a resource") end end)
And when I click the resource, the error occurs
wunt s0m3 b0rk? |
|
|
| Report Abuse |
|
|
96mg
|
  |
| Joined: 15 May 2017 |
| Total Posts: 775 |
|
|
| 25 Jul 2017 02:12 PM |
Replace hit with target, I was just testing it
wunt s0m3 b0rk? |
|
|
| Report Abuse |
|
|
INTELZEK
|
  |
| Joined: 29 Sep 2012 |
| Total Posts: 362 |
|
|
| 25 Jul 2017 02:14 PM |
I think this is the problem:
The hit you call as a variable in the function as a lower-case h, and the hit you use has an upper-case h. mouse.Hit is a CFrame value of where the mouse is in terms of the workspace
|
|
|
| Report Abuse |
|
|
INTELZEK
|
  |
| Joined: 29 Sep 2012 |
| Total Posts: 362 |
|
| |
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 25 Jul 2017 02:18 PM |
local player = game.Players.LocalPlayer local mouse = player:GetMouse() local resources = { ["Apple"] = true, ["Banana"] = true, ["Coconut"] = true, ["Glass Vial"] = true, ["Vial of Water"] = true, }
mouse.Button1Up:connect(function() local targ,hit = mouse.Target,mouse.Hit if targ then if resources[targ.Name] then print(player.Name,"has clicked a resource!") else print(targ.Name,"is not a resource") end else print("No target") end end) |
|
|
| Report Abuse |
|
|
96mg
|
  |
| Joined: 15 May 2017 |
| Total Posts: 775 |
|
|
| 25 Jul 2017 02:26 PM |
oh My, thanks @Soy
wunt s0m3 b0rk? |
|
|
| Report Abuse |
|
|