New rock module!
This module is an open source module that creates effect like rocks with tweening and good math abilities. This module uses part cache which helps enhance the performance for creating multiple parts to handle rock creating. As you can see there’s little to none of many rock modules on this platform so I aspired to make an effective one which gives the players access to good performance and limiting as well as debugging features.
This module does the following:
-
Uses good math components while keeping the script short and organized.
-
Does security checks and debugging for certain parameters.
-
Reassigns data for certain parameters if the value is nil or missing.
-
Uses Tween service to tween in and out.
Here is the link to the Module: RockModule - OPEN SOURCE - Roblox
Here is an example:
-- local script (has to be local script or it will error, server is not allowed)
local RockModule = require(game:GetService('ReplicatedStorage').RockModule)
local MyRocks = RockModule.new(
15, -- the amount of parts used for the rock. (15 is good)
Part.Position, -- Position to where the rocks are generated(vector3)
8, -- Magnitude basically the circle parameter
Vector3.new(3.5, 3.5, 3.5), -- part size (you might have to mess around with magnatude and partsize)
{game.Players.LocalPlayer.Character}, -- Filter parts you dont want to be recognized.
5) -- Destroy time
MyRocks:Generate()
Please comment some errors and the module will get updated constantly, This is open source and any changes can be made by you and there are many comments to help you understand in the script.
Source Code
-- Scripted by Flipitagainpls
--[[Easy to use Rock module.]]
local PartCache = require(script.PartCache)
local TweenService = game:GetService('TweenService')
local rocks = {}
local rocksMT = {__index = rocks}
local DEBUG_FOLDER = nil -- keeping tracks of the CacheParts after there placed in workspace
if not workspace:FindFirstChild('I%#$XDFS#') then
DEBUG_FOLDER = script['I%#$XDFS#']:Clone()
DEBUG_FOLDER.Parent = workspace
DEBUG_FOLDER.Name = 'I%#$XDFS#'
else
DEBUG_FOLDER = workspace['I%#$XDFS#']
end
function rocks.new(Amount , Pos, Radius, Size, filter, despawnTime)
local self = setmetatable({
Amount = Amount ,
Position = Pos,
Radius = Radius,
Size = Size,
Filter = filter,
Time = despawnTime
}, rocksMT)
return self
end
local t = {
CFrame.Angles(0, 2, 3),
CFrame.Angles(0, 3, 5),
CFrame.Angles(0, 4, 2)
} :: {CFrame}
local MISSING_ERROR = 'MISSING VARIABLE OR INDEX: ';
local function debug(Index)
error(MISSING_ERROR .. Index)
end
local function CFramePoint()
local c = t[math.random(1, #t)]
return c
end
local Cache = PartCache.new(Instance.new('Part'), 100 , script.Cache)
function rocks:Generate()
if game:GetService('RunService'):IsServer() then
error('PLEASE CALL ROCK MODULE ON CLIENT EX: FIREALLCLIENTS')
return -- Other rock modules allow server, its unnacceptable!
end
if not self.Amount then debug('Ammount') return end
if self.Amount >= 100 then
self.Amount = 15 -- lowers to 15 so partcache doesnt create much parts
end
if DEBUG_FOLDER then
local FilteredMaterial = RaycastParams.new()
FilteredMaterial.FilterType = Enum.RaycastFilterType.Exclude
FilteredMaterial.FilterDescendantsInstances = self.Filter
local angleIncrement, currentAngle = 2 * math.pi / self.Amount, 0
if not self.Size then
self.Size = Vector3.new(2, 2, 2)
end
coroutine.wrap(function()
for i = 1, self.Amount do
if not self.Radius then debug('Radius') return end
local offsetX = math.cos(currentAngle) * self.Radius
local offsetY = math.sin(currentAngle) * self.Radius
local Rock : Part = Cache:GetPart()
Rock.Size = Vector3.new(0, 0, 0)
Rock.Parent = DEBUG_FOLDER
Rock.CanCollide = false
TweenService:Create(Rock, TweenInfo.new(0.5), {Size = self.Size}):Play()
local ROCK_ROT = CFramePoint() :: CFrame -- returns a random cframe angle
Rock.Position = self.Position + Vector3.new(offsetX, 0, offsetY)
Rock.CFrame = Rock.CFrame * ROCK_ROT
currentAngle = currentAngle + angleIncrement
local Param = workspace:Raycast(Rock.Position, Vector3.new(0, -5, 0), FilteredMaterial)
if Param.Instance then
Rock.Material = Param.Instance.Material
Rock.Color = Param.Instance.Color
end
if not self.Time then
self.Time = 3
end
task.delay(self.Time, function()
TweenService:Create(Rock, TweenInfo.new(0.5), {Size = Vector3.new(0, 0, 0)}):Play()
task.delay(0.5, function() Cache:ReturnPart(Rock) end)
end)
end
end)()
end
end
return rocks