TNTxERIC
|
  |
| Joined: 20 Nov 2010 |
| Total Posts: 2689 |
|
|
| 25 Aug 2012 02:51 PM |
Hello I'm working on this rayscast script, but whenever it hits a hat it deals no damage to the characters health, and I don't know how to fix it. Please help; here is the script ( look at line 11 to 17):
local Tool = script.Parent --Set a variable for the tool. local User --Create a nil value for the character which we can't find yet. local enabled = true --The gun is ready Tool.Equipped:connect(function(mouse) --When it's equipped fire a function. mouse.Icon = "http://www.roblox.com/asset/?id=90302277" -- set the crosshair asset to the mouse icon User = Tool.Parent --Set the User variable to the character of the person using the tool. mouse.Button1Down:connect(function() --When the left mouse button is clicked fire a function. if enabled == true then --If the gun is ready then script.Parent.ShotSound:play() -- play the sound local Ray = Ray.new(Tool.Handle.CFrame.p,(mouse.Hit.p-Tool.Handle.CFrame.p).unit*300) --Make a the ray. local Hit,Position = game.Workspace:FindPartOnRay(Ray,User) --Check for collisions along the ray. if Hit then --If it hits something. if Hit.Parent:FindFirstChild("Humanoid") then --If the thing the ray hit has a humanoid. local Player = game.Players:GetPlayerFromCharacter(Hit.Parent) if(Player)then if Player.TeamColor ~= game.Players:GetPlayerFromCharacter(script.Parent.Parent).TeamColor then -- if the hit players doesn't share the same team as the shooter then Hit.Parent.Humanoid:TakeDamage(100) --Do 100 damage if they don't have a forcefield. mouse.Icon = "http://www.roblox.com/asset/?id=90302320" -- set the hitmarker asset to the mouse icon wait (3) -- wait 3 seconds mouse.Icon = "http://www.roblox.com/asset/?id=90302277" -- set the crosshair asset to the mouse icon end --End the humanoid check. end --End the hit check. end -- end the conditonal statement end -- end the conditonal statement local RayPart = Instance.new("Part",User) --Create a part in the user. RayPart.Name = "RayPart" --Set its name. RayPart.BrickColor = BrickColor.new("White") --Set its color. RayPart.Transparency = 0.5 --Set its transparency. RayPart.Anchored = true --Set whether it will fall or not. RayPart.CanCollide = false --Set whether people can walk though it or not. RayPart.TopSurface = Enum.SurfaceType.Smooth --Make it smooth on the top. RayPart.BottomSurface = Enum.SurfaceType.Smooth --Make it smooth on the bottom. RayPart.formFactor = Enum.FormFactor.Custom --Make it so it can be small. local Distance = (Position-Tool.Handle.CFrame.p).magnitude --Find the distance between the click and the gun. RayPart.Size = Vector3.new(0.2,0.2,Distance) --Set its size to the distance. RayPart.CFrame = CFrame.new(Position,Tool.Handle.CFrame.p) * CFrame.new(0,0,-Distance/2) --Move it halfway. game.Debris:AddItem(RayPart,0.1) --Add it to the debris. enabled = false --The gun isn't ready mouse.Icon = "http://www.roblox.com/asset/?id=90300354" -- set the reloading asset to the mouse icon wait(7) --Wait for the gun to be ready mouse.Icon = "http://www.roblox.com/asset/?id=90302277" -- set the crosshair asset to the mouse icon enabled = true --The gun is ready end -- end the conditonal statement end) -- end the equipped function end) -- end the clicked function
|
|
|
| Report Abuse |
|
|
Luc599345
|
  |
| Joined: 25 Jul 2008 |
| Total Posts: 1169 |
|
|
| 25 Aug 2012 03:17 PM |
You can loop trought every characters, and see if the object it hitted a descendant of the character, example
(Say hit is the object it hit)
for i,v in pairs(game:service'Players':GetPlayers()) do if hit:IsDescendantOf(v.Character) then -- damage end end |
|
|
| Report Abuse |
|
|
TNTxERIC
|
  |
| Joined: 20 Nov 2010 |
| Total Posts: 2689 |
|
|
| 25 Aug 2012 03:30 PM |
| I'm thinking of how to incorporate that into my script. |
|
|
| Report Abuse |
|
|
TNTxERIC
|
  |
| Joined: 20 Nov 2010 |
| Total Posts: 2689 |
|
|
| 25 Aug 2012 03:41 PM |
| Do I really need the loop or can I just use the IsDescdentOf method? |
|
|
| Report Abuse |
|
|
Luc599345
|
  |
| Joined: 25 Jul 2008 |
| Total Posts: 1169 |
|
|
| 25 Aug 2012 03:47 PM |
| Well, the loop is to loop trought every character, so... yes, pretty much. |
|
|
| Report Abuse |
|
|
RA2lover
|
  |
| Joined: 09 Nov 2008 |
| Total Posts: 1254 |
|
|
| 25 Aug 2012 03:53 PM |
| alternatively, you can include hats on the raycast ignore list. |
|
|
| Report Abuse |
|
|
TNTxERIC
|
  |
| Joined: 20 Nov 2010 |
| Total Posts: 2689 |
|
|
| 26 Aug 2012 08:27 PM |
@RA how do I do that?
-http://www.roblox.com/TNTxERIC-item?id=88273188- |
|
|
| Report Abuse |
|
|
TNTxERIC
|
  |
| Joined: 20 Nov 2010 |
| Total Posts: 2689 |
|
|
| 26 Aug 2012 08:42 PM |
Reading up on raycasting hopefully I will find an easier/more efficent way then the first reply was, and find out how to make the ray ignore, I should have done this before. *facepalm*
-http://www.roblox.com/TNTxERIC-item?id=88273188- |
|
|
| Report Abuse |
|
|
TNTxERIC
|
  |
| Joined: 20 Nov 2010 |
| Total Posts: 2689 |
|
|
| 26 Aug 2012 08:50 PM |
http://wiki.roblox.com/index.php/Raycasting_Basics -- very helpful article, time to modify my script. What why am I posting so much it's making me look like a noob.
-http://www.roblox.com/TNTxERIC-item?id=88273188- |
|
|
| Report Abuse |
|
|