generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: How do I get Mouse.Target.Name?

Previous Thread :: Next Thread 
96mg is not online. 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
Snixxus123 is not online. Snixxus123
Joined: 31 Mar 2011
Total Posts: 125
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 is not online. 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 is not online. XBLAX
Joined: 06 Apr 2012
Total Posts: 82
25 Jul 2017 02:08 PM
Mouse.Hit.Name?
Report Abuse
96mg is not online. 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
Lord_Oscar is online. Lord_Oscar
Joined: 15 Nov 2009
Total Posts: 17662
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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. INTELZEK
Joined: 29 Sep 2012
Total Posts: 362
25 Jul 2017 02:15 PM
Oh


Report Abuse
Soybeen is not online. 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 is not online. 96mg
Joined: 15 May 2017
Total Posts: 775
25 Jul 2017 02:26 PM
oh My, thanks @Soy


wunt s0m3 b0rk?
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image