Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Everything is working fine execpt this one part of my script, can someone help me fix it?

Asked by 7 years ago
Edited 7 years ago

Okay so everything below is working fine the part is being spawned, and the message is popping up. But the one thing that isn't working is when the part touches me it isn't killing me. I'm assuming it has something to do with the fact that the first thing it touches is the baseplate but other than that I'm not sure. And if you know how I can make the event occur only once when touching the part instead of numerous times instantaneously that'd be nice, thanks.------------

01function Cough(Part)
02local fries = Instance.new('Message')
03fries.Parent = game.Workspace
04fries.Text = "Hello I will now explode"
05wait(3)
06fries:Destroy()
07local explosion = Instance.new('Part', game.Workspace)
08Part = explosion
09Part.Anchored = true
10Part.Shape = 'Ball'
11Part.Transparency = 0.1
12Part.TopSurface = "Smooth"
13Part.BottomSurface = "Smooth"
14Part.CanCollide = false
15while true do
View all 34 lines...
0
You can just merge your 'death' function into 'Cough', like right after resizing the Part. User#17685 0 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

My Studio is updating right now, and my internet is being very slow at the moment, so take note that all of this is coming off the top of my head and I can't help it. That said, I hope I can still be of some help.

At line 22, a new variable is created that acts as the parameter for the function. Whatever the parameter is (hum in this case) will equal whatever the Touched event data relays onto it. So if it is touching the Baseplate, some brick, or your Left arm, the function will act upon those things. Since the Touched event is so general with the data its sending, you will want to control it within the function itself, not outside, once the general data has been passed onto "hum".

What you want to do now is control which parts get through. The function should check whatever it has been hit with before executing the rest of it.

01function death(hum)
02    if hum.Parent.Humanoid then -- this checks if the object "Humanoid" is a sibling of what it has touched, since the only thing that can do that is the body parts of a character.
03        local health = hum.Parent:FindFirstChild("Humanoid").Health -- creates a new variable for the health of the humanoid, since the touching part and the health are different
04        local fries = Instance.new("Message") -- it would be better to consolidate both functions into this one because they both activate once something touches it
05        fries.Parent == workspace --nowadays you don't even need the *game* part in it
06        fries.Text = "Hello I will now explode"
07        wait(3)
08        fries:Destroy()
09 
10        local explosion =  Instance.new("Part", workspace) --explosion doesn't need to equal Part since 1. The parameter for the function wasn't necessary and 2. renaming it isn't either
11        explosion.Anchored = true
12        explosion.Shape = "Ball" -- I forget if this is an Enumeration and not a value. Read more about it here: http://wiki.roblox.com/index.php?title=Enumeration
13        explosion.Transparancy = 0.1
14        explosion.TopSurface = Enum.SurfaceType.Smooth --An enumeration.
15        explosion.BottomSurface = Enum.SurfaceType.Smooth
View all 26 lines...

The last thing we need to do is connect the part's Touched event to the function.

1script.Parent.Touched:connect(death)

And that's it. Hopefully this works for you.

0
I appreciate your help seeing you don't have access to studio. Things work fine besides the damage portion. SacredEden 10 — 7y
Ad

Answer this question