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 » Scripters
Home Search
 

Re: Find a part?

Previous Thread :: Next Thread 
PsychonautX is not online. PsychonautX
Joined: 02 Feb 2011
Total Posts: 591
24 Dec 2015 09:51 PM
So basically what i'm trying to do is have this damage script search for a part(lets call it "box") in the player it hits and if it finds that "box" I want it to not damage the player. How would I accomplish this?

I'm sure I could do a findfirstchild but then how would I go about not damaging the hit player?







ball = script.Parent
damage = 25

debris = game:GetService("Debris")
debris:AddItem(ball, 10)

HitSound = Instance.new("Sound")
HitSound.Name = "HitSound"
HitSound.SoundId = "http://www.roblox.com/asset/?id=11945266"
HitSound.Pitch = .5
HitSound.Parent = ball




function onTouched(hit)
local humanoid = hit.Parent:findFirstChild("Humanoid")
connection:disconnect()
local bf = ball:FindFirstChild("BulletFloat")
if (bf ~= nil) then bf:Remove() end

if humanoid ~= nil then
tagHumanoid(humanoid)
humanoid:TakeDamage(damage)
end

HitSound:Play()


end

function tagHumanoid(humanoid)
-- todo: make tag expire
local tag = ball:findFirstChild("creator")
if tag ~= nil then
local new_tag = tag:clone()
new_tag.Parent = humanoid
debris:AddItem(new_tag, 1)
end
end



connection = ball.Touched:connect(onTouched)

Report Abuse
metologyaddict is not online. metologyaddict
Joined: 09 Dec 2015
Total Posts: 378
24 Dec 2015 09:59 PM
[ Content Deleted ]
Report Abuse
PsychonautX is not online. PsychonautX
Joined: 02 Feb 2011
Total Posts: 591
24 Dec 2015 10:05 PM
That's a pretty vague answer m8.
Report Abuse
AdvancedObjects is not online. AdvancedObjects
Joined: 11 Dec 2012
Total Posts: 3354
24 Dec 2015 10:06 PM
@Pyscho, it's better than nothing.
Report Abuse
metologyaddict is not online. metologyaddict
Joined: 09 Dec 2015
Total Posts: 378
24 Dec 2015 10:08 PM
[ Content Deleted ]
Report Abuse
BJCarpenter is not online. BJCarpenter
Joined: 04 Nov 2008
Total Posts: 4416
24 Dec 2015 10:10 PM
Something like this:




function onTouched(hit) -- hit is the Part that bullet hit.


local humanoid = hit.Parent:findFirstChild("Humanoid")
if hit ~= "box" then

connection:disconnect()
local bf = ball:FindFirstChild("BulletFloat")
if (bf ~= nil) then bf:Remove() end

if humanoid ~= nil then
tagHumanoid(humanoid)
humanoid:TakeDamage(damage)
end

HitSound:Play()

end -- hit box? -- or maybe, if u still want the Sound to play then put this above the previouse line


end -- function




Report Abuse
BJCarpenter is not online. BJCarpenter
Joined: 04 Nov 2008
Total Posts: 4416
24 Dec 2015 10:15 PM
*sorry might be (You ARE going to have to check this for errors by the way..................):


if hit.Name ~= "box" then
Report Abuse
PsychonautX is not online. PsychonautX
Joined: 02 Feb 2011
Total Posts: 591
24 Dec 2015 10:15 PM
@Advanced True enough
@Metology Thanks man, do you have any knowledge pertaining to the subject I was asking about in my first post though?
Report Abuse
metologyaddict is not online. metologyaddict
Joined: 09 Dec 2015
Total Posts: 378
24 Dec 2015 10:18 PM
[ Content Deleted ]
Report Abuse
PsychonautX is not online. PsychonautX
Joined: 02 Feb 2011
Total Posts: 591
24 Dec 2015 10:28 PM
@BJCarpenter Thanks for the help man, only one problem though. It seems that "connection" and tagHumanoid became unknown globals after testing your script i'll try to figure out how to fix it but any help you can provide would be greatly appreciated!
Report Abuse
PsychonautX is not online. PsychonautX
Joined: 02 Feb 2011
Total Posts: 591
24 Dec 2015 10:32 PM
Figured it out. Thanks m8.
Report Abuse
iUnEarthly is not online. iUnEarthly
Joined: 31 May 2012
Total Posts: 883
24 Dec 2015 10:34 PM
Another way, in the parent of where the part may be, do ":WaitForChild("box")" if it doesn't find it, it does nothing.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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