|
| 25 Jul 2016 01:00 PM |
while true do wait(1) bullet = Instance.new("Part", workspace) bullet.CanCollide = false bullet.CFrame = CFrame.new(-51, 7, 3) bullet.Anchored = true bullet.BrickColor = BrickColor.new("Bright yellow") bullet.Size = Vector3.new(0.5, 0.5, 5.56) for i=1, 30 do bullet.CFrame = bullet.CFrame + Vector3.new(0, 0, -5) wait(0.01) end bullet:Destroy() end
function onTouch(Hit) if Hit.parent:findFirstChild("Humanoid") ~= nil then Hit.Parent:findFirstChild("Humanoid").Health = Hit.Parent:findFirstChild("Humanoid").Health - 25 end end bullet.Touched:connect(onTouch)
this spawns a bullet near a part and it supposed to fly outward, and if u make contact with it you lose 25 health. It's not subtracting the health from the player... Could someone help? |
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 25 Jul 2016 01:09 PM |
Hit.parent:findFirstChild("Humanoid")
Capitalize Parent
Also use Humanoid:TakeDamage(25)
:)
|
|
|
| Report Abuse |
|
|
|
| 25 Jul 2016 01:16 PM |
@Soybeen it's not working still...
function onTouch(Hit) if Hit.Parent:findFirstChild("Humanoid") ~= nil then Hit.Parent:findFirstChild("Humanoid"):TakeDamage(25) end end bullet.Touched:connect(onTouch) |
|
|
| Report Abuse |
|
|
pyth_n
|
  |
| Joined: 21 Jun 2016 |
| Total Posts: 1322 |
|
| |
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 25 Jul 2016 01:21 PM |
I would use Raycasting too
Also the problem is resultant of your Touched function being outside of the portion that creates the bullet
So "linguistically" your code is saying:
- make a bullet - destroy the bullet - if the bullet touches anything, do damage
You need it to say
- make a bullet - if the bullet touches anything, do damage - destroy the bullet
So change your .Touched function to
bullet.Touched:connect(function(hit) if hit.Parent:findFirstChild("Humanoid") then hit.Parent:FindFirstChild("Humanoid"):TakeDamage(25) end end)
and put it right after you make the bullet instead of outside the loop.
|
|
|
| Report Abuse |
|
|
Thedagz
|
  |
| Joined: 10 Mar 2012 |
| Total Posts: 798 |
|
|
| 25 Jul 2016 01:22 PM |
Touch event does not work with cframe to do the damage you would cast a ray whenever your clicking and if the ray hits the player then subtract damage
Or
you could calculate the distance between the bullet and the player everytime it moves and once the distance is at a fair amount then take damage |
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 25 Jul 2016 01:23 PM |
That's true, you will need to change the Vector3 position of the bullet to damage the player, IIRC
|
|
|
| Report Abuse |
|
|
Thedagz
|
  |
| Joined: 10 Mar 2012 |
| Total Posts: 798 |
|
|
| 25 Jul 2016 01:24 PM |
What do you mean by change the vector 3 position?
if he uses vector3 inside of cframe then the bullet will go ontop of anything it collides with |
|
|
| Report Abuse |
|
|
pyth_n
|
  |
| Joined: 21 Jun 2016 |
| Total Posts: 1322 |
|
| |
|
Thedagz
|
  |
| Joined: 10 Mar 2012 |
| Total Posts: 798 |
|
|
| 25 Jul 2016 01:25 PM |
| ray casting would work but i think calculating distance between the bullet and the player is far easier |
|
|
| Report Abuse |
|
|
ISHOOTPPL
|
  |
| Joined: 06 Dec 2014 |
| Total Posts: 109 |
|
|
| 25 Jul 2016 01:28 PM |
Raycasting or BodyPosition/Velocity + Gyro is the way to go.
--Side note: :TakeDamage() is deprecated I'm pretty sure |
|
|
| Report Abuse |
|
|
pyth_n
|
  |
| Joined: 21 Jun 2016 |
| Total Posts: 1322 |
|
|
| 25 Jul 2016 01:28 PM |
ray casting would work but i think calculating distance between the bullet and the player is far easier
https://www.youtube.com/watch?v=WjBzRletLws
- pyth_n |
|
|
| Report Abuse |
|
|
Thedagz
|
  |
| Joined: 10 Mar 2012 |
| Total Posts: 798 |
|
|
| 25 Jul 2016 01:36 PM |
? Why would you use raycast when you can just do some simple subtraction to calculate distance?
|
|
|
| Report Abuse |
|
|
pyth_n
|
  |
| Joined: 21 Jun 2016 |
| Total Posts: 1322 |
|
|
| 25 Jul 2016 01:39 PM |
oh my god someone educate him i cant risk saying something mean and getting banned again
- pyth_n |
|
|
| Report Abuse |
|
|
Skellobit
|
  |
| Joined: 13 Apr 2016 |
| Total Posts: 12758 |
|
|
| 25 Jul 2016 01:39 PM |
exactly how I feel sometimes
Formerly ToxicDominator - add 17,509 posts |
|
|
| Report Abuse |
|
|
Thedagz
|
  |
| Joined: 10 Mar 2012 |
| Total Posts: 798 |
|
|
| 25 Jul 2016 01:41 PM |
| So instead of trying to correct me on my mistake that could potentially help me while making my own things I don't see how you have to say rude comments to educate me I don't mind taking some helpful advice |
|
|
| Report Abuse |
|
|
pyth_n
|
  |
| Joined: 21 Jun 2016 |
| Total Posts: 1322 |
|
|
| 25 Jul 2016 01:42 PM |
because you're not going to learn anything because you're not smart enough for programming, no offense.
- pyth_n |
|
|
| Report Abuse |
|
|
ISHOOTPPL
|
  |
| Joined: 06 Dec 2014 |
| Total Posts: 109 |
|
|
| 25 Jul 2016 01:43 PM |
Here goes @pyth_n
Ok. If you're going to embark on a project like making a gun first of all look up on google "roblox how 2 mak gun" and you will be directed to the wiki. From there change the damn variables on the color and crap and if you can't do that then you need to go back to the hospital and be born again. Thank you for reading..
I hope that helps @pyth_n, never been banned before :) |
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 25 Jul 2016 01:45 PM |
@Thedagz Ignore the internet trolls.
If they come to Scripters to belittle people with legitimate questions, then they don't deserve the time of day.
|
|
|
| Report Abuse |
|
|
Thedagz
|
  |
| Joined: 10 Mar 2012 |
| Total Posts: 798 |
|
|
| 25 Jul 2016 01:46 PM |
So for some reason you think raycasting on a moveing bullet would work how..?
As for the script above we don't know if his making a gun that why I don't believe ray casting is a good idea ALSO if he was making a gun his gun script so far does not look like a ray cast gun
All it doing is making parts in a loop then moving them with CFrame
So please explain to me how would raycast work in this circumstance |
|
|
| Report Abuse |
|
|
pyth_n
|
  |
| Joined: 21 Jun 2016 |
| Total Posts: 1322 |
|
|
| 25 Jul 2016 01:48 PM |
"So for some reason you think raycasting on a moveing bullet would work how..?"
you know nothing about raycasting. phantom forces uses raycasting. redux uses raycasting flux uses raycasting impulse uses raycasting.
every decently respectable gun engine i've seen uses raycasting.
- pyth_n |
|
|
| Report Abuse |
|
|
ISHOOTPPL
|
  |
| Joined: 06 Dec 2014 |
| Total Posts: 109 |
|
|
| 25 Jul 2016 01:48 PM |
| Well the only other way is with BodyGyro and BodyVelocity. |
|
|
| Report Abuse |
|
|
pyth_n
|
  |
| Joined: 21 Jun 2016 |
| Total Posts: 1322 |
|
|
| 25 Jul 2016 01:49 PM |
@Soybeen,
He knows jack squat and you know it.
- pyth_n |
|
|
| Report Abuse |
|
|
ISHOOTPPL
|
  |
| Joined: 06 Dec 2014 |
| Total Posts: 109 |
|
|
| 25 Jul 2016 01:50 PM |
| Newbie gun maker's backbone: http://wiki.roblox.com/index.php?title=Making_a_ray-casting_laser_gun |
|
|
| Report Abuse |
|
|
Thedagz
|
  |
| Joined: 10 Mar 2012 |
| Total Posts: 798 |
|
|
| 25 Jul 2016 01:51 PM |
I can agree that all of those games use ray casting for those guns
However the way those guns work is that they cast a ray
then make a bullet move along with that ray
But then how do they take damage?
They calculate the distance between the bullet and the player...
(Assuming that the bullet actually moves)
Most ray cast guns will automatically damage the player if the ray hits the player
This is when the bullet doesn't move and just make a brick and change the size.
There are also some guns that use raycast and make there bullet moves but they damage the player before the bullet even hits them...
And Again Phantom forces still calculate the distance between the bullet and the player
It seems like you don't know anything about Gun mechanics lol |
|
|
| Report Abuse |
|
|