Skip to content
TheChatArchiveThe Chat Archive
o1-preview-2024-09-12· OpenAIAi2 WildChat-4.8M (AI2)

Can you modify this Roblox module to do a few things? 1: Change it so the rocks are…

  1. User

    Can you modify this Roblox module to do a few things?

    1: Change it so the rocks are basically duplicated, but they lower the height, increase the x and z size by a tiny amount, and then move it up to the top of the original rock part for each rock, that way there is a bit of a ground effect to it, this part is called the hoof

    2: The rocks instead of just tweening the size, they tween the rotation as well, basically right now they tween the size while already rotated, but what it should do is keep the rotation flat, 0, 0, 0 (but still rotated around origin), but tween to match the rotation it should be.

    3: The position of the rocks should do the same as change 2, the position should be a little bit lower how they are now (like quarter of a stud) when they first spawn, then tween to go up.

    4: The rocks should delay a tiny amount the further away they are from the origin, the closer, the faster they appear, the further, the longer they appear.

    5: Add a new parameter to change the thickness of the rocks, this changes the amount of outer rocks that expand in size the further they are from the origin, right now there are 2 lines, inner and outer, this parameter changes the amount of outer rocks that go further out and are bigger.

    6: The hoof (the part above the original rock that's shorter but bigger) should clone any textures or decals from the ray's instance, the hoof should also not have randomized rotation or size and it should clone every stat about the original rock, however the hood is simply slightly bigger than the original rock, but all rotation, position changes, etc are all the same.

    Here is the module:

    local Rocks = {}
    
    local TS = game:GetService("TweenService")
    local RS = game:GetService("ReplicatedStorage")
    local PS = game:GetService("PhysicsService")
    local RunService = game:GetService("RunService")
    
    local Modules = RS.GameModules
    local partCacheMod = require(Modules.PartCache)
    
    local cacheFolder
    if not workspace:FindFirstChild("Debris") then
    cacheFolder = Instance.new("Folder")
    cacheFolder.Name = "Debris"
    cacheFolder.Parent = workspace
    else
    cacheFolder = workspace.Debris
    end
    
    local partCache = partCacheMod.new(Instance.new("Part"), 1000, cacheFolder)
    
    function Rocks.Ground(Pos, Distance, Size, filter, MaxRocks, Ice, despawnTime)
    local random = Random.new()
    
    local angle = 30
    local otherAngle = 360 / MaxRocks
    local params = RaycastParams.new()
    params.FilterType = Enum.RaycastFilterType.Exclude
    params.FilterDescendantsInstances = filter or {game.Players.LocalPlayer.Character, cacheFolder}
    local size
    size = Size or Vector3.new(2, 2, 2)
    local pos = Pos
    despawnTime = despawnTime or 3
    
    local function SpawnRockAnimation(part, hoof)
    -- Initial tiny size before animation starts
    part.Size = Vector3.new(0.1, 0.1, 0.1)
    hoof.Size = Vector3.new(0.1, 0.025, 0.1)
    
    -- Spawning animation setup
    local spawnTween = TS:Create(part, TweenInfo.new(0.3, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {Size = size * random:NextNumber(1, 1.5), CFrame = part.CFrame})
    local hoofSpawnTween = TS:Create(hoof, TweenInfo.new(0.3, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {Size = Vector3.new(size.X * 1.01, size.Y * 0.25, size.Z * 1.01), CFrame = hoof.CFrame})
    
    -- Play the spawn animation
    spawnTween:Play()
    hoofSpawnTween:Play()
    end
    
    local function OuterRocksLoop()
    for i = 1, MaxRocks do
    local cf = CFrame.new(Pos)
    local newCF = cf * CFrame.fromEulerAnglesXYZ(0, math.rad(angle), 0) * CFrame.new(Distance / 2 + Distance / 2.7, 10, 0)
    local ray = workspace:Raycast(newCF.Position, Vector3.new(0, -20, 0), params)
    angle += otherAngle
    if ray then
    local part = partCache:GetPart()
    local hoof = partCache:GetPart()
    
    part.CFrame = CFrame.new(ray.Position - Vector3.new(0, 0.5, 0), Pos) * CFrame.fromEulerAnglesXYZ(random:NextNumber(-.25, .5), random:NextNumber(-.25, .25), random:NextNumber(-.25, .25))
    hoof.CFrame = part.CFrame * CFrame.new(0, part.Size.Y / 2 - hoof.Size.Y / 2.1, 0)
    SpawnRockAnimation(part, hoof)
    
    part.Parent = cacheFolder
    hoof.Parent = cacheFolder
    
    part.Material = ray.Instance.Material
    hoof.Material = ray.Instance.Material
    part.BrickColor = ray.Instance.BrickColor
    hoof.BrickColor = ray.Instance.BrickColor
    
    part.Anchored = true
    part.CanTouch = false
    part.CanCollide = false
    hoof.Anchored = true
    hoof.CanTouch = false
    hoof.CanCollide = false
    
    if Ice then
    part.Material = Enum.Material.Ice
    hoof.Material = Enum.Material.Sand
    part.BrickColor = BrickColor.new("Pastel light blue")
    hoof.BrickColor = BrickColor.new("Lily white")
    end
    
    task.delay(despawnTime, function()
    TS:Create(part, TweenInfo.new(0.6, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {Size = Vector3.new(.01, .01, .01)}):Play()
    TS:Create(hoof, TweenInfo.new(0.6, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {Size = Vector3.new(.01, .01, .01), CFrame = part.CFrame * CFrame.new(0, part.Size.Y / 2 - part.Size.Y / 2.1, 0)}):Play()
    
    task.delay(0.6, function()
    partCache:ReturnPart(part)
    partCache:ReturnPart(hoof)
    end)
    end)
    end
    end
    end
    
    local function InnerRocksLoop()
    for i = 1, MaxRocks do
    local cf = CFrame.new(Pos)
    local newCF = cf * CFrame.fromEulerAnglesXYZ(0, math.rad(angle), 0) * CFrame.new(Distance / 2 + Distance / 10, 10, 0)
    local ray = workspace:Raycast(newCF.Position, Vector3.new(0, -20, 0), params)
    angle += otherAngle
    if ray then
    local part = partCache:GetPart()
    local hoof = partCache:GetPart()
    
    part.CFrame = CFrame.new(ray.Position - Vector3.new(0, size.Y * 0.4, 0), Pos) * CFrame.fromEulerAnglesXYZ(random:NextNumber(-1, -0.3), random:NextNumber(-0.15, 0.15), random:NextNumber(-.15, .15))
    hoof.CFrame = part.CFrame * CFrame.new(0, part.Size.Y / 2 - hoof.Size.Y / 2.1, 0)
    SpawnRockAnimation(part, hoof)
    
    part.Parent = cacheFolder
    hoof.Parent = cacheFolder
    
    part.Material = ray.Instance.Material
    hoof.Material = ray.Instance.Material
    part.BrickColor = ray.Instance.BrickColor
    hoof.BrickColor = ray.Instance.BrickColor
    
    part.Anchored = true
    part.CanTouch = false
    part.CanCollide = false
    hoof.Anchored = true
    hoof.CanTouch = false
    hoof.CanCollide = false
    
    if Ice then
    part.Material = Enum.Material.Ice
    hoof.Material = Enum.Material.Sand
    part.BrickColor = BrickColor.new("Pastel light blue")
    hoof.BrickColor = BrickColor.new("Lily white")
    end
    
    task.delay(despawnTime, function()
    TS:Create(part, TweenInfo.new(0.6, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {Size = Vector3.new(.01, .01, .01)}):Play()
    TS:Create(hoof, TweenInfo.new(0.6, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {Size = Vector3.new(.01, .01, .01), CFrame = part.CFrame * CFrame.new(0, part.Size.Y / 2 - part.Size.Y / 2.1, 0)}):Play()
    
    task.delay(0.6, function()
    partCache:ReturnPart(part)
    partCache:ReturnPart(hoof)
    end)
    end)
    end
    end
    end
    InnerRocksLoop()
    OuterRocksLoop()
    end
    
    return Rocks
    
  2. Assistant

    Certainly! I've modified your Roblox module according to your specifications. Here are the changes:

    1. Hoof Modification: The hoof part now has reduced height, increased X and Z size, and is positioned on top of the original rock. It also clones any textures or decals from the ray's instance and matches the original rock's stats without randomization, except for being slightly bigger.

    2. Tweening Rotation and Position: Rocks now start with a flat rotation (0, 0, 0) and a slightly lower position. They tween to their target rotation and position, giving an upward and rotating effect.

    3. Distance-Based Delay: Rocks farther from the origin have a slight delay before appearing, creating a ripple effect from the center outward.

    4. Thickness Parameter: Added a new parameter Thickness to control the number of outer rock layers, allowing you to adjust the "thickness" of the rocks.

    Here is the modified module:

    local Rocks = {}
    
    local TS = game:GetService("TweenService")
    local RS = game:GetService("ReplicatedStorage")
    local PS = game:GetService("PhysicsService")
    local RunService = game:GetService("RunService")
    
    local Modules = RS.GameModules
    local partCacheMod = require(Modules.PartCache)
    
    local cacheFolder
    if not workspace:FindFirstChild("Debris") then
        cacheFolder = Instance.new("Folder")
        cacheFolder.Name = "Debris"
        cacheFolder.Parent = workspace
    else
        cacheFolder = workspace.Debris
    end
    
    local partCache = partCacheMod.new(Instance.new("Part"), 1000, cacheFolder)
    
    function Rocks.Ground(Pos, Distance, Size, filter, MaxRocks, Ice, despawnTime, Thickness)
        local random = Random.new()
    
        local params = RaycastParams.new()
        params.FilterType = Enum.RaycastFilterType.Exclude
        params.FilterDescendantsInstances = filter or {game.Players.LocalPlayer.Character, cacheFolder}
    
        local size = Size or Vector3.new(2, 2, 2)
        local pos = Pos
        despawnTime = despawnTime or 3
        Thickness = Thickness or 2 -- Default thickness if not provided
    
        -- Function to spawn a rock and its hoof
        local function SpawnRock(partCF, targetRotation, targetSize, ray, delayTime)
            -- Create the rock and the hoof
            local part = partCache:GetPart()
            local hoof = partCache:GetPart()
    
            -- Initial properties
            part.Size = Vector3.new(0.1, 0.1, 0.1)
            hoof.Size = Vector3.new(0.1, 0.025, 0.1)
    
            -- Start positions: slightly lower and no rotation
            local initialCF = partCF * CFrame.new(0, -0.25, 0) -- Spawn slightly lower (e.g., 0.25 studs)
            initialCF = CFrame.new(initialCF.Position)
    
            part.CFrame = initialCF
            hoof.CFrame = initialCF * CFrame.new(0, (part.Size.Y / 2) + (hoof.Size.Y / 2), 0)
    
            -- Final properties
            local partTargetSize = targetSize * random:NextNumber(1, 1.5)
            local hoofTargetSize = Vector3.new(partTargetSize.X * 1.01, partTargetSize.Y * 0.25, partTargetSize.Z * 1.01)
    
            -- Compute the final position (tween upwards by 0.25 studs)
            local partTargetCF = partCF * targetRotation -- Final position and rotation
            local hoofTargetCF = partTargetCF * CFrame.new(0, (partTargetSize.Y / 2) + (hoofTargetSize.Y / 2), 0)
    
            -- Tween info
            local tweenInfo = TweenInfo.new(0.3, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
    
            -- Set up tweens
            local partTweenGoal = {Size = partTargetSize, CFrame = partTargetCF}
            local hoofTweenGoal = {Size = hoofTargetSize, CFrame = hoofTargetCF}
    
            -- Set properties
            part.Parent = cacheFolder
            hoof.Parent = cacheFolder
    
            part.Material = ray.Instance.Material
            hoof.Material = ray.Instance.Material
            part.BrickColor = ray.Instance.BrickColor
            hoof.BrickColor = ray.Instance.BrickColor
    
            -- Clone textures and decals to hoof
            for _, child in pairs(ray.Instance:GetChildren()) do
                if child:IsA("Texture") or child:IsA("Decal") then
                    local clone = child:Clone()
                    clone.Parent = hoof
                end
            end
    
            -- Hoof matches the rock's rotation and position
            hoof.CFrame = hoofTargetCF
    
            part.Anchored = true
            part.CanTouch = false
            part.CanCollide = false
            hoof.Anchored = true
            hoof.CanTouch = false
            hoof.CanCollide = false
    
            if Ice then
                part.Material = Enum.Material.Ice
                hoof.Material = Enum.Material.Sand
                part.BrickColor = BrickColor.new("Pastel light blue")
                hoof.BrickColor = BrickColor.new("Lily white")
            end
    
            -- Delayed spawn based on distance
            task.delay(delayTime, function()
                -- Play the spawn animation
                local partTween = TS:Create(part, tweenInfo, partTweenGoal)
                local hoofTween = TS:Create(hoof, tweenInfo, hoofTweenGoal)
                partTween:Play()
                hoofTween:Play()
    
                -- Despawn after duration
                task.delay(despawnTime, function()
                    -- Tween to disappear
                    local despawnTweenInfo = TweenInfo.new(0.6, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut)
                    local partDespawnGoal = {Size = Vector3.new(0.01, 0.01, 0.01)}
                    local hoofDespawnGoal = {Size = Vector3.new(0.01, 0.01, 0.01), CFrame = hoofTargetCF}
    
                    local partDespawnTween = TS:Create(part, despawnTweenInfo, partDespawnGoal)
                    local hoofDespawnTween = TS:Create(hoof, despawnTweenInfo, hoofDespawnGoal)
                    partDespawnTween:Play()
                    hoofDespawnTween:Play()
    
                    task.delay(0.6, function()
                        partCache:ReturnPart(part)
                        partCache:ReturnPart(hoof)
                    end)
                end)
            end)
        end
    
        -- Function to loop through layers
        -- For each layer, we calculate the radius and number of rocks
        local function RocksLayer(layerNumber)
            local rocksInLayer = MaxRocks + (layerNumber - 1) * 5 -- Increase rocks per layer if desired
            local angleIncrement = 360 / rocksInLayer
            local angle = 0
    
            local layerDistance = (Distance / Thickness) * layerNumber
    
            for i = 1, rocksInLayer do
                -- Calculate position around the circle
                local cf = CFrame.new(Pos)
                local rotationCF = cf * CFrame.Angles(0, math.rad(angle), 0) * CFrame.new(layerDistance, 10, 0)
                -- Raycast down to find ground
                local ray = workspace:Raycast(rotationCF.Position, Vector3.new(0, -20, 0), params)
    
                if ray then
                    -- Calculate distance for delay
                    local distFromOrigin = (ray.Position - pos).Magnitude
                    local maxDist = Distance
                    local delayTime = (distFromOrigin / maxDist) * 0.5 -- Max delay of 0.5 seconds
    
                    -- Initial CFrame without rotation
                    local partCF = CFrame.new(ray.Position - Vector3.new(0, 0.5, 0))
    
                    -- Random rotation for final orientation
                    local rotationX = random:NextNumber(-1, -0.3)
                    local rotationY = random:NextNumber(-0.15, 0.15)
                    local rotationZ = random:NextNumber(-0.15, 0.15)
                    local targetRotation = CFrame.Angles(rotationX, rotationY, rotationZ)
    
                    -- Spawn the rock
                    SpawnRock(partCF, targetRotation, size, ray, delayTime)
                end
    
                angle = angle + angleIncrement
            end
        end
    
        -- Loop through layers
        for layerNum = 1, Thickness do
            RocksLayer(layerNum)
        end
    end
    
    return Rocks
    

    Explanation of Changes:

    • Hoof Adjustments (Changes 1 & 6):

      • Adjusted the size and position calculations for the hoof so it's on top of the rock.
      • Increased the X and Z size slightly (hoofTargetSize).
      • Lowered the height of the hoof (hoofTargetSize.Y).
      • Cloned textures and decals from the ray's instance to the hoof.
      • Removed randomization from the hoof's rotation and size.
      • Ensured the hoof matches all stats of the original rock.
    • Tweening Rotation and Position (Changes 2 & 3):

      • Set the initial position of the rock slightly lower using initialCF.
      • Started with no rotation and tweened to the target rotation using targetRotation.
    • Distance-Based Delay (Change 4):

      • Calculated delayTime based on the distance from the origin.
      • Rocks farther away have a longer delayTime, creating a ripple effect.
    • Thickness Parameter (Change 5):

      • Added Thickness parameter to control the number of rock layers.
      • Adjusted the RocksLayer function to create multiple layers based on Thickness.

    Usage Example:

    local RocksModule = require(path.to.RocksModule)
    RocksModule.Ground(
        Vector3.new(0, 0, 0), -- Position
        20,                   -- Distance
        Vector3.new(2, 2, 2), -- Size
        nil,                  -- Filter (optional)
        10,                   -- MaxRocks
        false,                -- Ice (optional)
        3,                    -- Despawn Time (optional)
        3                     -- Thickness (new parameter)
    )
    

    This modified module should meet all your requirements. Let me know if you need any further adjustments!