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: Raycasting gun issue.

Previous Thread :: Next Thread 
Valone is not online. Valone
Joined: 08 Feb 2012
Total Posts: 4371
01 Apr 2012 04:26 AM
So, this is the script inside my gun, works perfectly but, when you go into first person, your mouse picks up the gun, so it shoots back on itself, or sends rays sprawling it. This can be seen at my Unit 32 outpost alpha.

I need the mouse to ignore the gun parts. I've tried target filter on the tool but I got "Bad cast"

Settings = {
ShotSound = 2697294,
ReloadSound = 2697432,
Beams = 1,
Automatic = false,
Damage = 10,
Accurate = true,
Clip = 30,
Reload = 3, --Minimum 1
Range = 200,
BeamColor = "Navy blue"
}

---------------------------------------------------------------------------------------------------
-----------------Do not touch below here unless you know what you are doing.----------------------
---------------------------------------------------------------------------------------------------

wait()

Tool = script.Parent
Player = script.Parent.Parent.Parent
ThyName = Tool.Name
Turret = Tool.Shoot
Down = false
On = false
Ammo = Settings.Clip
Gui = script.Parent.Gui
Realoading = false
Tags = {}
ToolOn = false

local ShootSound = Instance.new("Sound")
ShootSound.SoundId = "http://www.roblox.com/asset/?id="..Settings.ShotSound
ShootSound.Parent = Turret
ShootSound.Volume = 0.3
ShootSound.Pitch = 1.2

local ReloadSound = Instance.new("Sound")
ReloadSound.SoundId = "http://www.roblox.com/asset/?id="..Settings.ReloadSound
ReloadSound.Parent = Turret
ReloadSound.Volume = 0.6
ReloadSound.Pitch = 0.7

Gui.Name = ThyName.."Gui"
Gui.Frame.Title.Text = ThyName

function fire(mouse)
ShootSound:play()
local Pos0 = Turret.Position
local Pos1 = mouse.Hit.p
if Settings.Accurate == false then
Pos1 = mouse.Hit.p+Vector3.new(math.random(1,3)-math.random(1,3),math.random(1,3)-math.random(1,3),math.random(1,3)-math.random(1,3))
end
if (Pos0-Pos1).magnitude < Settings.Range+1 then
Ammo = Ammo-1
local Hit, Pos1 = game.Workspace:FindPartOnRay(Ray.new(Turret.Position,CFrame.new(Turret.Position,Pos1).lookVector*Settings.Range),script.Parent.Parent)
if Hit ~= nil and Hit.Parent ~= nil then
if Hit.Parent.className == "Hat" and Hit.Parent.Parent:FindFirstChild("Humanoid") ~= nil then
Hit.Parent.Parent.Humanoid.Health = Hit.Parent.Parent.Humanoid.Health-Settings.Damage
local Tag = Instance.new("ObjectValue",Hit.Parent.Parent.Humanoid)
Tag.Name = "creator"
Tag.Value = game.Players:playerFromCharacter(Tool.Parent)
elseif Hit.Parent:FindFirstChild("Humanoid") ~= nil then
Hit.Parent.Humanoid.Health = Hit.Parent.Humanoid.Health-Settings.Damage
local Tag = Instance.new("ObjectValue",Hit.Parent.Humanoid)
Tag.Name = "creator"
Tag.Value = game.Players:playerFromCharacter(Tool.Parent)
end
end
local Laser = Instance.new("Part")
Laser.BrickColor = BrickColor.new(Settings.BeamColor)
Laser.Name = "Ray"
Laser.Reflectance = 0.1
Laser.Anchored = true
Laser.CanCollide = false
Laser.Size = Vector3.new(1, 1, 1)
local LaserMesh = Instance.new("BlockMesh")
Laser.CFrame = CFrame.new(Pos0, Pos1)
LaserMesh.Offset = Vector3.new(0, 0, -((Pos0 - Pos1).magnitude/2))
LaserMesh.Scale = Vector3.new(0.15, 0.15, (Pos0 - Pos1).magnitude)
LaserMesh.Parent = Laser
Laser.Parent = Workspace
for i = 1,15 do
wait()
local Pos0 = Turret.Position
Laser.CFrame = CFrame.new(Pos0, Pos1)
LaserMesh.Offset = Vector3.new(0, 0, -((Pos0 - Pos1).magnitude/2))
LaserMesh.Scale = Vector3.new(LaserMesh.Scale.X-0.01, LaserMesh.Scale.Y-0.01, (Pos0 - Pos1).magnitude)
Laser.Transparency = Laser.Transparency+0.05
end
Game:GetService("Debris"):AddItem(Laser, .25)
Game:GetService("Debris"):AddItem(Tag, 2)
end
end

function onButton1Down(mouse)
print(Ammo)
if On == false and Ammo > 0 and Realoading == false then
On = true
Down = true
if Settings.Automatic == false then
for i = 1,Settings.Beams do
coroutine.resume(coroutine.create(function ()
fire(mouse)
end))
Gui.Frame.Ammo.Text = tostring(Ammo).."/"..tostring(Settings.Clip)
end
else
while Down == true and Ammo > 0 do
wait(0.1)
for i = 1,Settings.Beams do
coroutine.resume(coroutine.create(function ()
fire(mouse)
end))
Gui.Frame.Ammo.Text = tostring(Ammo).."/"..tostring(Settings.Clip)
end
end
end
wait(0.2)
On = false
end

end

function keyDown(key,mouse)
if key == "r" and Realoading == false then
mouse.Icon = "rbxasset://textures\\GunWaitCursor.png"
Realoading = true
Gui.Frame.Ammo.Text = "0/"..tostring(Settings.Clip)
for i = 1,5 do
Tool.GripForward = Tool.GripForward+Vector3.new(0,0.04,0)
wait()
end

ReloadSound:play()
for i = 1,10 do
Tool.Parent.Torso.LAW.C1 = Tool.Parent.Torso.LAW.C1+Vector3.new(0,-0.05,0)
wait()
end
for i = 1,10 do
Tool.Parent.Torso.LAW.C1 = Tool.Parent.Torso.LAW.C1+Vector3.new(0,0.05,0)
wait()
end
wait(Settings.Reload-(0.03*20))
Ammo = Settings.Clip
Realoading = false
for i = 1,5 do
Tool.GripForward = Tool.GripForward+Vector3.new(0,-0.04,0)
wait()
end
Gui.Frame.Ammo.Text = tostring(Ammo).."/"..tostring(Settings.Clip)
if ToolOn == true then
mouse.Icon = "rbxasset://textures\\GunCursor.png"
end
end
end

function onButton1Up()
Down = false
end

Tool.Equipped:connect(function (mouse)
ToolOn = true
Gui.Parent = Player.PlayerGui
Gui.Frame.Ammo.Text = tostring(Ammo).."/"..tostring(Settings.Clip)
mouse.Icon = "rbxasset://textures\\GunCursor.png"
mouse.TargetFilter = script.Parent.Shoot
mouse.Button1Down:connect(function () onButton1Down(mouse) end)
mouse.Button1Up:connect(function () onButton1Up() end)
mouse.KeyDown:connect(function (key) keyDown(key,mouse) end)
end)

Tool.Unequipped:connect(function ()
ToolOn = false
Gui.Parent = script
end)



☜▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬☜☆☞▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬☞
-Valone 32nd Empress of Unit 32. Join; http://www.roblox.com/My/Groups.aspx?gid=520434
Report Abuse
mrbossyboots1337 is not online. mrbossyboots1337
Joined: 27 Sep 2008
Total Posts: 3790
01 Apr 2012 06:05 AM
I get that sometimes, make the barrel parts uncancollided.

if that doesent work...I personally cant help.
Report Abuse
Darkmist101 is not online. Darkmist101
Joined: 30 Jul 2010
Total Posts: 6208
01 Apr 2012 07:28 AM
Learn to code,
please.

wiki.roblox.com
Report Abuse
kirkyturky12 is not online. kirkyturky12
Joined: 30 Apr 2010
Total Posts: 1915
01 Apr 2012 07:42 AM
game.Workspace:FindPartOnRay(Ray.new(Turret.Position,CFrame.new(Turret.Position,Pos1).lookVector*Settings.Range),script.Parent.Parent)

This line should ignore your gun. The script.Parent.Parent is the ignore part. Is that the right parenting, because script.Parent.Parent should be the tool.
Report Abuse
Valone is not online. Valone
Joined: 08 Feb 2012
Total Posts: 4371
01 Apr 2012 08:08 AM
@Dark, I'm pretty sure I can, with that.
@Kirky, yep, that didn't work. Wouldn't help anyway, as it's the mouse.

☜▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬☜☆☞▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬☞
-Valone 32nd Empress of Unit 32. Join; http://www.roblox.com/My/Groups.aspx?gid=520434
Report Abuse
kirkyturky12 is not online. kirkyturky12
Joined: 30 Apr 2010
Total Posts: 1915
01 Apr 2012 08:10 AM
Can you even script?
Report Abuse
MrNicNac is not online. MrNicNac
Joined: 29 Aug 2008
Total Posts: 26567
01 Apr 2012 08:23 AM
The mouse only naturally ignores your character model, this is why people put plane models into your character.

The mouse should never hit the gun as long as every part of it is a child of your character (player.Character, Workspace.Player). Also, you will need to lock every part of the gun.
Report Abuse
Valone is not online. Valone
Joined: 08 Feb 2012
Total Posts: 4371
01 Apr 2012 08:34 AM
Thank you MrNicNac, I appreciate it.

☜▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬☜☆☞▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬☞
-Valone 32nd Empress of Unit 32. Join; http://www.roblox.com/My/Groups.aspx?gid=520434
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