Can you modify this Roblox module to do a few things? 1: Change it so the rocks are…
- 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
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
- Assistant
Here's the modified Roblox module incorporating the requested changes:
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) despawnTime = despawnTime or 3 thickness = thickness or 2 -- Default thickness local maxDelay = 0.5 -- Maximum delay based on distance -- Function to spawn rock animation with rotation and position tweening local function SpawnRockAnimation(part, hoof, finalCFrame, hoofFinalCFrame, levelSizeMultiplier) -- Initial tiny size and flat rotation before animation starts local initialPosition = finalCFrame.Position - Vector3.new(0, 0.25, 0) local initialCFrame = CFrame.new(initialPosition) part.CFrame = initialCFrame part.Size = Vector3.new(0.1, 0.1, 0.1) -- Hoof initial setup local hoofInitialPosition = hoofFinalCFrame.Position - Vector3.new(0, 0.25, 0) local hoofInitialCFrame = CFrame.new(hoofInitialPosition) hoof.CFrame = hoofInitialCFrame hoof.Size = Vector3.new(0.1, 0.025, 0.1) -- Spawning animation setup (tweening size, rotation, and position) local spawnTween = TS:Create(part, TweenInfo.new(0.3, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), { Size = size * random:NextNumber(1, 1.5) * levelSizeMultiplier, CFrame = finalCFrame }) local hoofSpawnTween = TS:Create(hoof, TweenInfo.new(0.3, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), { Size = Vector3.new(size.X * 1.01 * levelSizeMultiplier, size.Y * 0.25, size.Z * 1.01 * levelSizeMultiplier), CFrame = hoofFinalCFrame }) -- Play the spawn animation spawnTween:Play() hoofSpawnTween:Play() end -- Function to handle rocks at different levels (thickness) local function RocksLoop(level) local angle = 30 local rocksPerLevel = MaxRocks local otherAngle = 360 / rocksPerLevel for i = 1, rocksPerLevel do local cf = CFrame.new(Pos) -- Calculate the offset distance for this level local offsetDistance = (Distance / 2) + ((level - 1) * (Distance / (2 * thickness))) local newCF = cf * CFrame.fromEulerAnglesXYZ(0, math.rad(angle), 0) * CFrame.new(offsetDistance, 10, 0) local ray = workspace:Raycast(newCF.Position, Vector3.new(0, -20, 0), params) angle += otherAngle if ray then local distanceFromOrigin = (ray.Position - Pos).Magnitude local delayTime = math.clamp((distanceFromOrigin / (Distance * 1.5)) * maxDelay, 0, maxDelay) task.delay(delayTime, function() local part = partCache:GetPart() local hoof = partCache:GetPart() -- Calculate final CFrame with desired rotation local randomRotation = CFrame.fromEulerAnglesXYZ(random:NextNumber(-.25, .5), random:NextNumber(-.25, .25), random:NextNumber(-.25, .25)) local finalCFrame = CFrame.new(ray.Position - Vector3.new(0, 0.5, 0), Pos) * randomRotation -- Hoof final CFrame placed on top of the part local hoofFinalCFrame = finalCFrame * CFrame.new(0, size.Y * 0.5 * (1 + (level - 1) * 0.1) - (size.Y * 0.25) / 2, 0) -- Level size multiplier based on thickness level local levelSizeMultiplier = 1 + ((level - 1) * 0.1) -- Spawn the animation SpawnRockAnimation(part, hoof, finalCFrame, hoofFinalCFrame, levelSizeMultiplier) -- Set parent and 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 part.Anchored = true part.CanTouch = false part.CanCollide = false hoof.Anchored = true hoof.CanTouch = false hoof.CanCollide = false -- Clone any textures or decals from the ray's instance to the hoof for _, child in ipairs(ray.Instance:GetChildren()) do if child:IsA("Texture") or child:IsA("Decal") then local clonedChild = child:Clone() clonedChild.Parent = hoof end end 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 -- Schedule despawn after spawn delay plus despawnTime task.delay(despawnTime, function() -- Tween to despawn 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 end -- Loop through each level based on thickness for level = 1, thickness do RocksLoop(level) end end return RocksExplanation of Changes:
-
Duplicated Rocks (Hoof): The
hoofpart is set up to be a duplicated rock with adjusted size (lower height, increased X and Z size) and is positioned on top of the original rock part. This creates the ground effect, and thehoofrepresents this part. -
Tweening Rotation and Position:
- In
SpawnRockAnimation, the initial CFrame of the part is set to have no rotation (CFrame.new(initialPosition)) and is slightly lower than the final position. - The tween now includes changing the
CFramefrom the initial flat rotation and lower position to the final desired rotation and position (finalCFrame). - This makes the rocks appear to grow and rotate into place during the spawn animation.
- In
-
Initial Lower Position and Tween Upward:
- The rocks are initially placed slightly below their final positions (
initialPosition = finalCFrame.Position - Vector3.new(0, 0.25, 0)), and during the tween, they move upward to their final positions.
- The rocks are initially placed slightly below their final positions (
-
Delay Based on Distance from Origin:
- A
delayTimeis calculated proportional to the distance from the origin (Pos). Rocks farther from the origin have a longer delay before they appear. - This is implemented using
task.delay(delayTime, function() ... end)when spawning each rock.
- A
-
Thickness Parameter:
- A new parameter
thicknessis added to control the number of rock layers expanding outward from the origin. - Instead of separate inner and outer loops, a single loop iterates over the thickness levels, adjusting the
offsetDistanceandlevelSizeMultiplierfor each level. - Rocks in outer levels are placed further out and are larger, creating the expanding effect.
- A new parameter
-
Cloning Textures/Decals to Hoof:
- After setting the
MaterialandBrickColorof thehoof, anyTextureorDecalinstances from theray.Instanceare cloned and parented to thehoof. - This ensures that the
hoofpart visually matches any textures or decals present on the original surface.
- After setting the
Usage:
When calling
Rocks.Ground, you can now specify thethicknessparameter to control the number of rock layers:Rocks.Ground( Position, -- The central position Distance, -- The base distance for rocks Size, -- Base size of the rocks Filter, -- Objects to exclude from raycasting MaxRocks, -- Number of rocks per layer Ice, -- Whether to use ice materials/colors DespawnTime, -- Time before rocks despawn Thickness -- Number of layers of rocks )This updated module should meet all the specified requirements, providing enhanced visual effects for the rocks in your Roblox game.
-