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

can make fire ball do 10 damage instead of completely killing the dummy ?

Asked by 10 years ago

i dont want it to be able to harm other players

r = game:service("RunService")

shaft = script.Parent
position = shaft.Position

function fly()
    direction = shaft.CFrame.lookVector 
    position = position + (direction*2)
    error = position - shaft.Position
    shaft.Velocity = error * 7
end

function blow()
    swoosh:stop()
    explosion = Instance.new("Explosion")
    explosion.Position = shaft.Position



    local creator = script.Parent:findFirstChild("creator")
    if creator ~= nil then
        explosion.Hit:connect(function(part, distance)  onPlayerBlownUp(part, distance, creator) end)
    end

    explosion.Parent = game.Workspace
    connection:disconnect()
    wait(.5)
    shaft:remove()
end

function onPlayerBlownUp(part, distance, creator)

    if part.Name == "Head" then

        local humanoid = part.Parent:findFirstChild("Humanoid")
        tagHumanoid(humanoid, creator)
    end
end

function tagHumanoid(humanoid, creator)


    if creator ~= nil then
        local new_tag = creator:clone()
        new_tag.Parent = humanoid

    end
end

function untagHumanoid(humanoid)
    if humanoid ~= nil then
        local tag = humanoid:findFirstChild("creator")
        if tag ~= nil then

            tag.Parent = nil
        end
    end
end

t, s = r.Stepped:wait()

swoosh = script.Parent.Swoosh
swoosh:play()

d = t + 10.0 - s
connection = shaft.Touched:connect(blow)

while t < d do
    fly()
    t = r.Stepped:wait()
end


script.Parent.Explosion.PlayOnRemove = false
swoosh:stop()
shaft:remove()

1 answer

Log in to vote
0
Answered by 10 years ago

So i see you have an explosion method to kill (rocket), not easy to do it, but ik a way. I'm gonna use forcefield at normal players so it doesn't kill them. Take a look at our complete script:

r = game:service("RunService")

shaft = script.Parent
position = shaft.Position

function fly()
    direction = shaft.CFrame.lookVector 
    position = position + (direction*2)
    error = position - shaft.Position
    shaft.Velocity = error * 7
end

function FFNormalPlayers(target) -- Target will be our part
        local playe = game:service('Players'):GetPlayerFromCharacter(target) -- get player

        if (playe ~=nil ) then -- Player exists!
        for i,v in pairs(game:service('Players'):GetChildren()) do -- Every player is not harmed
        local char = v.Character
        if (char~=nil) then -- Isn't punished
        if (v.userId~=playe.userId) then -- Not hit player
        Instance.new('ForceField',char)
        end end
        end end
        wait(.1)
        for i,v in pairs(game:service('Players'):GetChildren()) do -- Another loop
        local char = v.Character
        if (char~=nil) then -- Character exists
        for a,e in pairs(char:GetChildren()) do -- Character instances
        if e:IsA('ForceField') then -- Forcefield
        e:Destroy() -- Remove
        end
        end
        end
end

shaft.Touched:connect(function(p) -- Rocket is touched
if (p.Name~="Torso" and p.Name~="Head") then -- Check if it's a player character
blow(p) -- Blow up
end
end)

function blow(killin)
    swoosh:stop()
    explosion = Instance.new("Explosion")
    explosion.Position = shaft.Position

    FFNormalPlayers(killin)-- The function we made above.

    local creator = script.Parent:findFirstChild("creator")
    if creator ~= nil then
        explosion.Hit:connect(function(part, distance)  onPlayerBlownUp(part, distance, creator) end)
    end

    explosion.Parent = game.Workspace
    connection:disconnect()
    wait(.5)
    shaft:remove()
end

function onPlayerBlownUp(part, distance, creator)

    if part.Name == "Head" then

        local humanoid = part.Parent:findFirstChild("Humanoid")
        tagHumanoid(humanoid, creator)
    end
end

function tagHumanoid(humanoid, creator)


    if creator ~= nil then
        local new_tag = creator:clone()
        new_tag.Parent = humanoid

    end
end

function untagHumanoid(humanoid)
    if humanoid ~= nil then
        local tag = humanoid:findFirstChild("creator")
        if tag ~= nil then

            tag.Parent = nil
        end
    end
end

t, s = r.Stepped:wait()

swoosh = script.Parent.Swoosh
swoosh:play()

d = t + 10.0 - s
connection = shaft.Touched:connect(blow)

while t < d do
    fly()
    t = r.Stepped:wait()
end


script.Parent.Explosion.PlayOnRemove = false
swoosh:stop()
shaft:remove()


Hope this works! ~marcoantoniosantos3

Ad

Answer this question