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 » Scripting Helpers
Home Search
 

Re: How to get position of mouse

Previous Thread :: Next Thread 
GiraffeRaging is not online. GiraffeRaging
Joined: 12 Sep 2010
Total Posts: 1861
30 Jul 2014 10:31 PM
Using getmouse, how do I refer to the position of the mouse? This is what I tried.

script.Parent.Selected:connect(function(m)
m.Button1Down:connect(function()
if m.Target then
local kaboomage = Instance.new("Explosion")
kaboomage.Parent = Workspace
kaboomage.Position = m.Target
end
end)
end)
Report Abuse
haloisabeast is not online. haloisabeast
Joined: 28 Jun 2009
Total Posts: 366
30 Jul 2014 10:34 PM
http://wiki.roblox.com/index.php?title=Hit_(Property)
Report Abuse
Accomplishable is not online. Accomplishable
Joined: 13 Aug 2009
Total Posts: 6207
30 Jul 2014 10:36 PM
You should use ray casting.



script.Parent.Selected:connect(function(m)
m.Button1Down:connect(function()
if m.Target then
local kaboomage = Instance.new("Explosion")
kaboomage.Parent = Workspace
kaboomage.Position = m.Hit.p
end
end)
end)
Report Abuse
alij12 is not online. alij12
Joined: 03 Oct 2011
Total Posts: 1204
30 Jul 2014 10:36 PM
mouse = game.Players.LocalPlayer:GetMouse() --local script; gets mouse

pos = mouse.hit.p --gets the position
Report Abuse
GiraffeRaging is not online. GiraffeRaging
Joined: 12 Sep 2010
Total Posts: 1861
30 Jul 2014 10:36 PM
Thanks kind-of. Told me of a property I didn't know about, not how to use it.

I tried this.

script.Parent.Selected:connect(function(m)
m.Button1Down:connect(function()
if m.Target then
local kaboomage = Instance.new("Explosion")
kaboomage.Parent = Workspace
kaboomage.Position = m.Hit
end
end)
end)
Report Abuse
GiraffeRaging is not online. GiraffeRaging
Joined: 12 Sep 2010
Total Posts: 1861
30 Jul 2014 10:38 PM
Oh, I see, thanks guys.

I assume .p means .Position?

Also, where can I learn about raycasting? I have no idea what it is or how to use it.
Report Abuse
haloisabeast is not online. haloisabeast
Joined: 28 Jun 2009
Total Posts: 366
30 Jul 2014 10:40 PM
http://wiki.roblox.com/index.php?title=Raycasting

have you used the wiki before? if not, AMAZING place to learn all things scripting/building :) wiki.roblox.com
Report Abuse
GiraffeRaging is not online. GiraffeRaging
Joined: 12 Sep 2010
Total Posts: 1861
30 Jul 2014 10:51 PM
While were on the subject of this script, this was my attempt at making infinite explosions until the user let go of their mouse.

It didn't work, what should I have done?

script.Parent.Selected:connect(function(m)
m.Button1Down:connect(function()
if m.Target then
repeat
wait()
local kaboomage = Instance.new("Explosion")
kaboomage.DestroyJointRadiusPercent = .2
kaboomage.BlastRadius = 15
kaboomage.Parent = Workspace
kaboomage.Position = m.Hit.p
kaboomage.BlastPressure = 999999
until m.Button1Up
end
end)
end)
Report Abuse
Accomplishable is not online. Accomplishable
Joined: 13 Aug 2009
Total Posts: 6207
30 Jul 2014 10:54 PM
local Button = false;
script.Parent.Selected:connect(function(m)
m.Button1Down:connect(function()
Button = true;
if m.Target then
repeat
wait()
local kaboomage = Instance.new("Explosion")
kaboomage.DestroyJointRadiusPercent = .2
kaboomage.BlastRadius = 15
kaboomage.Parent = Workspace
kaboomage.Position = m.Hit.p
kaboomage.BlastPressure = 999999
until not Button
end
end)
end)
Mouse.Button1Up:connect(function()
Button = false;
end)
Report Abuse
GiraffeRaging is not online. GiraffeRaging
Joined: 12 Sep 2010
Total Posts: 1861
30 Jul 2014 11:03 PM
That worked to a very small extent unfortunately.

After removing the habitual semicolons and changing "Mouse" to "m", it works in a glitchy way in studio, not at all in game.


This is the error I get.

Players.Player1.Backpack.Explode (Admin).Script:16: attempt to index global 'm' (a nil value)

local Button = false
script.Parent.Selected:connect(function(m)
m.Button1Down:connect(function()
Button = true
if m.Target then
repeat
wait()
local kaboomage = Instance.new("Explosion")
kaboomage.BlastRadius = 15
kaboomage.Parent = Workspace
kaboomage.Position = m.Hit.p
until not Button
end
end)
end)
m.Button1Up:connect(function()
Button = false
end)
Report Abuse
Accomplishable is not online. Accomplishable
Joined: 13 Aug 2009
Total Posts: 6207
30 Jul 2014 11:18 PM
Woops. forgot to put the button 1 up event inside the equipped event


local Button = false
script.Parent.Selected:connect(function(m)
m.Button1Down:connect(function()
Button = true
if m.Target then
repeat
wait()
local kaboomage = Instance.new("Explosion")
kaboomage.BlastRadius = 15
kaboomage.Parent = Workspace
kaboomage.Position = m.Hit.p
until not Button
end
end)
m.Button1Up:connect(function()
Button = false
end)
end)
Report Abuse
GiraffeRaging is not online. GiraffeRaging
Joined: 12 Sep 2010
Total Posts: 1861
30 Jul 2014 11:20 PM
I noticed that too and fixed it, but it only works in studios with no errors. In game there is no explosion.

local Button = false
script.Parent.Selected:connect(function(m)
m.Button1Down:connect(function()
m.Button1Up:connect(function()
Button = false
end)
Button = true
if m.Target then
repeat
wait()
local kaboomage = Instance.new("Explosion")
kaboomage.BlastRadius = 15
kaboomage.Parent = Workspace
kaboomage.Position = m.Hit.p
until not Button
end
end)
end)
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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