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: (Guns) Help with dealing damage to players w/ Hats

Previous Thread :: Next Thread 
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
26 Sep 2014 08:52 PM
I've been trying for hours, I really can't get this. Someone, please help. I've been trying forever to deal damage through the hat to the player. I've tried everything. Someone be my savior pleaaase.

function Fire(Mouse)
local Spread = CFrame.Angles(math.rad(math.random(-Settings.Spread, Settings.Spread)/10), math.rad(math.random(-Settings.Spread, Settings.Spread)/10), math.rad(math.random(-Settings.Spread, Settings.Spread)/10))
local Ray = Ray.new(Character.Head.Position, (CFrame.new(Character.Head.Position, Mouse.Hit.p) * Spread).lookVector.unit * Settings.Range)
local Hit, Pos = game.Workspace:FindPartOnRayWithIgnoreList(Ray, Ray_Ignore)
local HumanoidFinder1 = Hit.Parent:FindFirstChild("Humanoid") or Hit.Parent:IsA("Hat")
if Hit and HumanoidFinder1 then
local Hit_Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
if Settings.AntiTK and not Hit_Player.Neutral and Hit_Player.TeamColor == Player.TeamColor then
return
end
local Humanoid1 = Hit.Parent.Humanoid
local c = Instance.new("ObjectValue")
c.Name = "creator"
c.Value = Player
game.Debris:AddItem(c, 3)
c.Parent = Humanoid1
if Hit.Name == "Head" then
Humanoid1.Health = Humanoid1.Health - (Settings.HeadShotDamage)
else if Hit.Parent:IsA("Hat") then
Hit.Parent.Parent.Humanoid.Health = Hit.Parent.Parent.Humanoid.Health - (Settings.Damage)
else
Humanoid1.Health = Humanoid1.Health - (Settings.Damage)
end
end
Report Abuse
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
26 Sep 2014 09:03 PM
if you help me I will love you forever
Report Abuse
IAmTheRolo is online. IAmTheRolo
Joined: 12 Nov 2013
Total Posts: 859
26 Sep 2014 09:06 PM
local HumanoidFinder1 = Hit~=nil and Hit.Parent:FindFirstChild("Humanoid") or Hit~=nil and Hit.Parent.Parent:FindFirstChild("Humanoid")
Report Abuse
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
26 Sep 2014 09:07 PM
@IAm

Output:

Humanoid is not a valid member of Hat
Report Abuse
IAmTheRolo is online. IAmTheRolo
Joined: 12 Nov 2013
Total Posts: 859
26 Sep 2014 09:09 PM
You didn't just change that single line, right? HumanoidFinder1 is now either the humanoid or nil.
Report Abuse
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
26 Sep 2014 09:14 PM
I just changed the single line
Report Abuse
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
26 Sep 2014 09:27 PM
I really don't know how to fix this code

I tried
Report Abuse
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
26 Sep 2014 10:11 PM
I have fixed the hats issue

The ONLY issue remaining is that whenever you shoot into nothing/space/air, you break the script. Any quick fix? I'll put the output at the bottom. (The last elseif creates a dot if it didn't hit a humanoid, so a bullet mark)

function Fire(Mouse)
local Spread = CFrame.Angles(math.rad(math.random(-Settings.Spread, Settings.Spread)/10), math.rad(math.random(-Settings.Spread, Settings.Spread)/10), math.rad(math.random(-Settings.Spread, Settings.Spread)/10))
local Ray = Ray.new(Character.Head.Position, (CFrame.new(Character.Head.Position, Mouse.Hit.p) * Spread).lookVector.unit * Settings.Range)
local Hit, Pos = game.Workspace:FindPartOnRayWithIgnoreList(Ray, Ray_Ignore)

local HumanoidFinder1 = Hit.Parent:FindFirstChild("Humanoid")
local HumanoidFinder2 = Hit.Parent:IsA("Hat")
print'past line 1'
if (HumanoidFinder1 or HumanoidFinder2) then
print'past line 2'
local Hit_Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
if Settings.AntiTK and not Hit_Player.Neutral and Hit_Player.TeamColor == Player.TeamColor then
return
end
print'past all that non-sense'
local c = Instance.new("ObjectValue")
c.Name = "creator"
c.Value = Player
game.Debris:AddItem(c, 3)
c.Parent = Hit.Parent:FindFirstChild("Humanoid") or Hit.Parent.Parent:FindFirstChild("Humanoid")
if Hit.Parent:IsA("Hat") then
print'past if statement'
Hit.Parent.Parent.Humanoid.Health = Hit.Parent.Parent.Humanoid.Health - (Settings.HeadShotDamage)
print'past damage'
elseif Hit.Name == "Head" then
Hit.Parent.Humanoid.Health = Hit.Parent.Humanoid.Health - (Settings.HeadShotDamage)
elseif Hit.Parent:FindFirstChild("Humanoid") then
print'past else'
Hit.Parent.Humanoid.Health = Hit.Parent.Humanoid.Health - (Settings.Damage)
print'past damage'
end
elseif Hit then
local Hit_Part = Instance.new("Part", Ignore_Model)
Hit_Part.FormFactor = "Custom"
Hit_Part.Material = "SmoothPlastic"
Hit_Part.TopSurface = 0
Hit_Part.BottomSurface = 0
Hit_Part.Anchored = true
Hit_Part.CanCollide = false
Hit_Part.Size = Vector3.new()
Hit_Part.CFrame = CFrame.new(Pos) * CFrame.Angles(math.random(0, 360), math.random(0, 360), math.random(0, 360))
Hit_Part.BrickColor = BrickColor.new("Black")
game.Debris:AddItem(Hit_Part, Settings.ImpactDuration)

Output:
Gun_Script:143: attempt to index local 'Hit' (a nil value)
Report Abuse
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
26 Sep 2014 10:26 PM
:)
Report Abuse
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
27 Sep 2014 11:18 AM
Bumpity bump
Report Abuse
OzzyFin is not online. OzzyFin
Joined: 07 Jun 2011
Total Posts: 3600
27 Sep 2014 11:20 AM
someone came with an alt

lold

Anyway you could just check if hit is not nil.
Report Abuse
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
27 Sep 2014 11:25 AM
Got it working
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