|
| 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 |
|
|
| |
|
|
| 24 Dec 2015 10:05 PM |
| That's a pretty vague answer m8. |
|
|
| Report Abuse |
|
|
|
| 24 Dec 2015 10:06 PM |
| @Pyscho, it's better than nothing. |
|
|
| Report Abuse |
|
|
| |
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
| |
|
|
| 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 |
|
|
|
| 24 Dec 2015 10:32 PM |
| Figured it out. Thanks m8. |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|