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

How do you make something shoot at a random person touching a part?

Asked by
parkderp1 105
9 years ago

Im trying to make something shoot at a random person touching a part, and I have no idea why my script isnt working ive debugged it and everything. This is in a normal script.

Here's the script:

potentialtarg={""}
ready=false
function onTouch(part)
    local hum=part.Parent:FindFirstChild("Humanoid")
    if hum~=nil then
    local name=part.Parent.Name
    for i=1, #potentialtarg do
        if name~=potentialtarg[i] then
    table.insert(potentialtarg,1,name)
        end
    end
end
end
script.Parent.Touched:connect(onTouch)

function onExit(part)
    local human=part.Parent:FindFirstChild("Humanoid")
    if human~=nil then
        local nombre=part.Parent.Name
        for i=1,#potentialtarg do
            if nombre==potentialtarg[i] then
                table.remove(potentialtarg,i)
            end
        end
    end
end

script.Parent.TouchEnded:connect(onExit)

function Fire()
    for i=1,#potentialtarg do
        local targ=math.random(potentialtarg[i])
        local target=targ.Torso
        local new=Instance.new("Part",game.Workspace)
        new.name="Fireball"
        new.Position = CFrame.new(46.4, 4.3, -53)
        new.Size = Vector3.new(3,3,3)
        local rock=Instance.new("RocketPropulsion",game.Workspace.Fireball) 
        rock.MaxSpeed=100
        new.RocketPropulsion.Target = target 
        ready = true    
    end
end



z=5
while true do
    if ready==true then
    Fire()
    wait(10)
    end
end


Answer this question