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.------------

function Cough(Part)
local fries = Instance.new('Message')
fries.Parent = game.Workspace
fries.Text = "Hello I will now explode"
wait(3)
fries:Destroy()
local explosion = Instance.new('Part', game.Workspace)
Part = explosion
Part.Anchored = true
Part.Shape = 'Ball'
Part.Transparency = 0.1
Part.TopSurface = "Smooth"
Part.BottomSurface = "Smooth"
Part.CanCollide = false
while true do
Part.Size = Part.Size + Vector3.new(1,1,1)
wait()
end

end
local hum = game.Workspace.Brick.Script.Parent:FindFirstChild("Humanoid")
function death(hum)
    if hum ~=nil then
        hum.Health = 0
end


end

script.Parent.Touched:connect(Cough)
if
    game.Workspace.Cough:connected() then
    death()
end
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.

function death(hum)
    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.
        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
        local fries = Instance.new("Message") -- it would be better to consolidate both functions into this one because they both activate once something touches it
        fries.Parent == workspace --nowadays you don't even need the *game* part in it
        fries.Text = "Hello I will now explode"
        wait(3)
        fries:Destroy()

        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
        explosion.Anchored = true
        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
        explosion.Transparancy = 0.1
        explosion.TopSurface = Enum.SurfaceType.Smooth --An enumeration.
        explosion.BottomSurface = Enum.SurfaceType.Smooth
        explosion.CanCollide == false
        for i=1, 10 do -- This will prevent it from growing infinitely, unless you want it to look like a nuclear explosion.
            explosion.Size =  explosion.Size + Vector3.new(1, 1, 1)
            wait()
            if i>10 do
                explosion:Destroy()
            end
        end
        health = 0 
    end
end

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

script.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