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

Functions within FindPartInRegion3WithWhitelist not working?

Asked by 5 years ago
Edited 5 years ago

I have this remote event for whenever a player is in the Region3 of an arena I made, and I want certain attack functions to perform whenever the player is in the Region3. I set up a remote event for it, and when the player is in the Region3, a bool value is set to true, and is fired to the server. On the server event, certain attack functions are supposed to happen, but they don't happen. I even had prints say the function was working, and that worked, but the function never happened.

Server script

InRange = false

function ShootingArc(plrtorso,plr)
    if not InRange then return end


        local mouse = plr:GetMouse()
        local hrp = plr.Character:WaitForChild("HumanoidRootPart")
        local t = 1
        local g = Vector3.new(0, -game.Workspace.Gravity, 0);
        local x0 = script.Parent.HumanoidRootPart.CFrame * Vector3.new(0, 0,-10)

        local v0 = (plrtorso.Position - x0 - 0.5*g*t*t)/t;

        local Star = game.ReplicatedStorage.MagicItems.Particles.BlazeMagic.Fire:Clone()
        Star.Name = "SunComet"
        Star.Anchored = false
        Star.CanCollide = false
        Star.Parent = workspace.MagicParts
        Star.CFrame = CFrame.new(x0)
        Star.Velocity = v0
        Star.SunExplosion.Enabled = false
        Star.Size = Vector3.new(7,7,7)

    Star.Touched:Connect(function(hit)
        if hit.Parent == script.Parent then return end
        Star:Destroy()

        local h = hit.Parent:FindFirstChild("Humanoid")
        local pv = hit.Parent:FindFirstChild("PlayerSV")

        if h ~= nil then

        if pv ~= nil then

        print((Star.Position - hit.Parent.Torso.Position).magnitude)
        if (Star.Position - hit.Parent.Torso.Position).magnitude <= 60 then
            h:TakeDamage(800)

        end
    end
end

        local Sun = Instance.new("Part")
        Sun.Parent = workspace.MagicParts
        Sun.Material = "Neon"
        Sun.BrickColor = BrickColor.new("Deep orange")
        Sun.Position = Star.Position
        Sun.Shape = "Ball"
        Sun.Size = Vector3.new(0,0,0)
        Sun.Transparency = 0
        Sun.CanCollide = false
        Sun.Anchored = true

        --local SunPE = game.Workspace.Fire.SunExplosion:Clone()
        --SunPE.Parent = Sun
        --SunPE.Enabled = true

        for i = 1, 30 do

            Sun.Size = Sun.Size + Vector3.new(4,4,4)
            --Sun.Transparency = Sun.Transparency + 0.05


            wait()
        end

    game.Debris:AddItem(Sun,.05)
    end)

    game.Debris:AddItem(Star,10)    
    wait(2)
end

game.ReplicatedStorage.AreaRegions["Theos' Arena"].RemoteEvent.OnServerEvent:Connect(function(plr,InRegion)
    if InRegion == false then return end
    local char = plr.Character or plr.CharacterAdded:Wait()
    while true do
        wait(1)

        if InRegion == true then
            ShootingArc(char.Torso,plr)
            print("InRegion true for Theos' Arena")
            print(ShootingArc)
        else
            return 
        end
    end
end)

The local script

InRegion = false

for i,v in pairs(game.ReplicatedStorage.AreaRegions:GetChildren())  do

    local X = math.abs(v.Point1.Position.X-v.Point2.Position.X) 
    local X2 = (v.Point1.Position.X+v.Point2.Position.X)/2
    local Y = math.abs(v.Point1.Position.Y-v.Point2.Position.Y) 
    local Y2 = (v.Point1.Position.Y+v.Point2.Position.Y)/2
    local Z = math.abs(v.Point1.Position.Z-v.Point2.Position.Z) 
    local Z2 = (v.Point1.Position.Z+v.Point2.Position.Z)/2
    local size = (Vector3.new(X,Y,Z))/2 
    local pos = Vector3.new(X2,Y2,Z2)
    local reg = Region3.new(pos - size, pos + size)
    local whitelist = {c.HumanoidRootPart}
spawn(function()
    while wait(1) do
        InRegion = false
        local n = workspace:FindPartsInRegion3WithWhiteList(reg,whitelist,10)

        for _,v2 in pairs(n) do
            if v2.Parent:FindFirstChild("Humanoid") and v2.Parent == c and v2.Name == "HumanoidRootPart" then
                local plr = game.Players:GetPlayerFromCharacter(v2.Parent) 
                InRegion = true

                if plr.AreaConfig.Area.Value ~= v.Name then
                    plr.AreaConfig.Area.Value = v.Name
                    MusicChange(v.Music)
                    AmbientChange(v.Config)
                    v.RemoteEvent:FireServer(InRegion)
                end
            end
        end
    end
end)
end

Answer this question