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

My script cant detect player (above certain height) how fix?

Asked by
ym5a 52
3 years ago
local lm = script.Parent:FindFirstChild("lightninMakers")
wait()
local function getIndex(tbl,item)
    for index, value in pairs(tbl) do
        if value == item then
            return index
        end
    end
end
local function getHighTingz() 
    local Table = {}
    local PlrTable = {}
    for i,v in pairs(game.Workspace:GetDescendants()) do
        if v:IsA("BasePart") then
            if v.Position.Y >= 50 and v:FindFirstAncestor("mapTIngz") == nil and v.Name ~= "stormtig" and game.Players:GetPlayerFromCharacter(v.Parent) == nil then
                table.insert(Table,(#Table+1),v)
                print(v)
            end
        elseif v:IsA("Part") and v.Parent:FindFirstChild("Humanoid") ~= nil and v.Position.Y >= 50 then
            print("hello")
            table.insert(PlrTable,(#PlrTable+1),v)
            local char = game.Players:GetPlayerFromCharacter(v.Parent) 
            print(char)
            char.CharacterRemoving:connect(function()
                local itemIndex = getIndex()
                print(PlrTable[itemIndex])
                table.remove(PlrTable,itemIndex)
            end)
        end
    end
    return Table, PlrTable
end
local function getMetallicThings()
    --
end
for i = 0,math.random(1,20) do
    local cl = game.ReplicatedStorage.stormtig:Clone()
    cl.Parent = lm
end
local function floree(numb)
    return math.floor(numb + 0.5)
end
local function tweenaroni(p)
    local t = game:GetService("TweenService"):Create(p,TweenInfo.new(0.1,Enum.EasingStyle.Linear),{Transparency = 1})
    t:Play()
    t.Completed:connect(function()
        p:Remove()
    end)
end
local function ligamentationasmarianismistation(part)
    local points = {}
    local parts = {}
    local foldor = Instance.new("Folder")
    foldor.Name = "lll"
    foldor.Parent = workspace
    local raycastResult = workspace:Raycast(part,Vector3.new(0,-1000,0))
    if raycastResult then
        if raycastResult.Instance:FindFirstAncestor("mapTIngz") == nil and raycastResult.Instance:IsA("BasePart") and raycastResult.Instance ~= game.Workspace:FindFirstChild("thunderstormCloud") then
            raycastResult.Instance:BreakJoints()
            local exp = Instance.new("Explosion")
            exp.BlastRadius = 2
            exp.BlastPressure = 20  --Explosion at the Raycast Instance position
            exp.Visible = false
            exp.Position = raycastResult.Instance.Position
            exp.Parent = workspace.Folder
            exp.ExplosionType = Enum.ExplosionType.NoCraters
            --raycastResult.Instance.Anchored = false
        end
    end
    local roundedNumb
    if raycastResult then
        roundedNumb = floree((part - raycastResult.Position).Magnitude /8)
    elseif raycastResult == nil then
        return nil
    end
    for i = 0, roundedNumb do
        local offset = Vector3.new(math.random(-5,5),math.random(-5,5),math.random(-5,5))
        if i == 0 or i == roundedNumb then
            offset = Vector3.new()
        end
        local lightBlock = game.ReplicatedStorage.lightningPart:Clone()
        local pos = part + (raycastResult.Position-part).Unit * i * (raycastResult.Position-part).Magnitude / roundedNumb 
        lightBlock.Position = pos + offset
        lightBlock.Parent = foldor
        local tog = pos+offset
        points[#points+1] = tog
        lightBlock.Touched:connect(function(h)
            if h.Parent:FindFirstChild("Humanoid") ~= nil then
                h.Parent:FindFirstChild("Humanoid"):TakeDamage(100)
            end
        end)
    end
    for i = 1,#points do
        if points[i+1] ~= nil then
            local lin = game.ReplicatedStorage.lightningPart:Clone()
            lin.CFrame = CFrame.new((points[i]+points[i+1])/2,points[i+1])
            lin.Size = Vector3.new(.5,.5,(points[i]-points[i+1]).Magnitude)
            lin.Parent = foldor

        end
    end
    local exp = Instance.new("Explosion")
    exp.BlastPressure = 20
    exp.BlastRadius = 2
    exp.Position = points[#points] --The explosion at the last Point of lightning
    exp.DestroyJointRadiusPercent = 1
    exp.Parent = workspace.Folder
    exp.ExplosionType = Enum.ExplosionType.NoCraters
    wait(.1)

    for i,v in pairs(foldor:GetChildren()) do
        tweenaroni(v)
    end
    wait(.1)
    foldor:Remove()
end
while true do
    wait()
    local tingTable, plrTable = getHighTingz()

    --spawn(function()
    for i,v in pairs(lm:GetChildren()) do
        if v:IsA("Part") then
            ligamentationasmarianismistation(v.Position)
            v.Position = v.Position + Vector3.new(0,-15,0)
        end
    end
    --end)

    for i,v in pairs(lm:GetChildren()) do
        local ViktorRykov = Vector3.new(math.random(-254,254),200,math.random(-255,255))
        spawn(function()
            wait(math.random(1,3))
            if v:IsA("Part") then 
                local n = math.random(1,20)
                if n ~= 20 then
                    print("Not chosen")
                    v.Position = ViktorRykov
                elseif n== 20 and #tingTable >= 1 or #plrTable >= 1 then
                    print(#tingTable)
                    local chosen = tingTable[math.random(1,#tingTable)]
                    local chosen1
                    if #plrTable >= 1 then
                        chosen1 = plrTable[math.random(1,#plrTable)]
                    end
                    local mr = math.random(1,2)
                    if mr == 1 then
                        print(mr)
                        v.Position = Vector3.new(chosen.Position.X,v.Position.Y,chosen.Position.Z)
                    elseif mr == 2 and #plrTable >= 1 then
                        print(mr)
                        v.Position = Vector3.new(chosen1.Position.X,v.Position.Y,chosen1.Position.Z)
                    end
                end
            end
        end)
    end
end
game.ServerScriptService.eventos.Event.Event:Connect(function(msg)
    if msg == "noLightning" then
        for i,v in pairs(lm:GetChildren()) do
            v:Remove()
        end
    end
end)


This is a thunderstorm script. it does not print hello . I wont be answering right now but just leave answers pls and any errors or suggestions ill answer tmrw thanks bye

Answer this question