I found a module script on the toolbox, modified it so it could take textures & whether it could collide, but it seems that the tween was either already broken or I broke it?
Looking for help to fix this bug. This is the module script’s entire script:
local Debris = game:GetService("Debris")
local CraterGenerator = {}
CraterGenerator.__index = CraterGenerator
function CraterGenerator.new(rad, numberOfTimes, Size, maxParts, center, sizeIncrement, Material:Enum.Material, Color, CanCollide, Texture)
if not rad or not numberOfTimes or not Size or not maxParts or not center or not sizeIncrement or not Material or not Color then
error("failed cause missing params")
end
local CurrentCrater = {}
setmetatable(CurrentCrater, CraterGenerator)
local RandomNumber = math.random(1,999)
local anticrash = 0
local function anticrasher()
if anticrash > 5 then
task.wait(5)
anticrash = 0
end
end
local function AntiDuper()
local AntiDupe = game.Workspace:FindFirstChild("Crater"..tostring(RandomNumber))
if AntiDupe then
RandomNumber = math.Random(1,999)
AntiDuper()
anticrash += 1
anticrasher()
end
end
local CraterSize = rad
local CraterCountPart = maxParts
local craterFolder = Instance.new("Folder")
craterFolder.Name = "Crater" .. tostring(RandomNumber)
craterFolder.Parent = game.Workspace
for i = 1, numberOfTimes do
local newCraterFolder = Instance.new("Folder")
newCraterFolder.Parent = craterFolder
newCraterFolder.Name = "CraterFolder" .. i
local NewCraterSize = i == 1 and rad or rad + sizeIncrement * (i - 1)
local newCraterCountPart = i == 1 and maxParts or maxParts * (i - 1)
local radius = NewCraterSize
local numParts = maxParts
local center = center
for j = 1, numParts do
local angle = math.random() * 2 * math.pi
local x = center.X + radius * math.cos(angle)
local z = center.Z + radius * math.sin(angle)
local part = Instance.new("Part")
part.Size = Size
part.Color = Color
part.Material = Material
if Texture then
local function createtexture(side)
local newtexture = Texture:Clone()
newtexture.Face = side
newtexture.Parent = part
end
createtexture(Enum.NormalId.Top)
createtexture(Enum.NormalId.Bottom)
createtexture(Enum.NormalId.Left)
createtexture(Enum.NormalId.Right)
createtexture(Enum.NormalId.Front)
createtexture(Enum.NormalId.Back)
end
part.Transparency = 0
part.Position = Vector3.new(x, center.Y, z) - Vector3.new(0,4.5, 0)
part.Anchored = true
part.Orientation = Vector3.new(math.random(-180, 180), math.random(-180, 180), math.random(-180, 180))
part.CanCollide = CanCollide
part.Parent = newCraterFolder
end
end
CurrentCrater.Object = craterFolder
return CurrentCrater
end
function Tween(inst, ti, prop)
game:GetService("TweenService"):Create(inst,ti,prop):Play()
end
function CraterGenerator:SpawnCrater(TTime, lifeTime, EaseInStyle, EaseInDirection, EaseOutStyle, EaseOutDirection)
if not TTime or not lifeTime or not EaseInStyle or not EaseInDirection or not EaseOutStyle or not EaseOutDirection then
end
local delayTime = 0
for _, v in self.Object:GetChildren() do
for i, part in v:GetChildren() do
Tween(part, TweenInfo.new(TTime, EaseInStyle, EaseInDirection), {Position = part.Position + Vector3.new(0, 20, 0)})
Debris:AddItem(part, (((TTime * 3) * #self.Object:GetChildren()) + lifeTime))
end
task.wait(delayTime)
Debris:AddItem(v, (((TTime * 3) * #self.Object:GetChildren()) + lifeTime))
end
task.wait(lifeTime)
for _, v in self.Object:GetChildren() do
for i, part in v:GetChildren() do
Tween(part, TweenInfo.new(TTime, EaseOutStyle, EaseOutDirection), {Position = part.Position - Vector3.new(0, 20, 0)})
end
task.wait(delayTime)
end
task.wait(TTime)
self.Object:Destroy()
end
return CraterGenerator
This is the local script I’m using to fire the module script:
local event = game.ReplicatedStorage.DebrisActivator
local module = require(game.ReplicatedStorage.CraterModule)
event.OnClientEvent:Connect(function(createtype,rad, numberOfTimes, Size, maxParts, center, sizeIncrement, Material, Color, CanCollide, Texture)
if createtype == 'new' then
module.new(rad, numberOfTimes, Size, maxParts, center, sizeIncrement, Material, Color, CanCollide, Texture)
end
if createtype == 'tween' then
module:SpawnCrater(rad,numberOfTimes,Size,maxParts,center,sizeIncrement)
end
end)
And this is the script I used inside a tool to relay info to an event:
remote:FireAllClients('new',5,1,Vector3.new(5,5,3),10,part.Parent.HumanoidRootPart.CFrame.Position,2,hit2.Material,darkenedcolor, false, texture)
remote:FireAllClients('tween',1,3,Enum.EasingStyle.Sine,Enum.EasingDirection.Out,Enum.EasingStyle.Sine,Enum.EasingDirection.In)
Every time I try and run it, it gives me this error:
ReplicatedStorage.CraterModule:102: attempt to index nil with 'GetChildren'
Stack Begin
Script 'ReplicatedStorage.CraterModule', **Line 102** - function SpawnCrater
Script 'Players.(me).PlayerScripts.Debris Service', **Line 9**
So, to summarize the blocks, it tries to get the children created by the script that had created the solid parts of the rubble, defined here
local CraterSize = rad
local CraterCountPart = maxParts
local craterFolder = Instance.new("Folder")
craterFolder.Name = "Crater" .. tostring(RandomNumber)
craterFolder.Parent = game.Workspace
Not sure if related, but here are 2 other bits that call on the craterFolder, this one being at the end:
CurrentCrater.Object = craterFolder
return CurrentCrater
end
and this one being at the beginning:
local Debris = game:GetService("Debris")
local CraterGenerator = {}
CraterGenerator.__index = CraterGenerator
function CraterGenerator.new(rad, numberOfTimes, Size, maxParts, center, sizeIncrement, Material:Enum.Material, Color, CanCollide, Texture)
if not rad or not numberOfTimes or not Size or not maxParts or not center or not sizeIncrement or not Material or not Color then
error("failed cause missing params")
end
local CurrentCrater = {}
setmetatable(CurrentCrater, CraterGenerator)
And it calls on the children of the above bits with this, failing on the first line I put here:
for _, v in self.Object:GetChildren() do
for i, part in v:GetChildren() do
Tween(part, TweenInfo.new(TTime, EaseInStyle, EaseInDirection), {Position = part.Position + Vector3.new(0, 20, 0)})
Debris:AddItem(part, (((TTime * 3) * #self.Object:GetChildren()) + lifeTime))
end
task.wait(delayTime)
Debris:AddItem(v, (((TTime * 3) * #self.Object:GetChildren()) + lifeTime))
end
task.wait(lifeTime)
for _, v in self.Object:GetChildren() do
for i, part in v:GetChildren() do
Tween(part, TweenInfo.new(TTime, EaseOutStyle, EaseOutDirection), {Position = part.Position - Vector3.new(0, 20, 0)})
end
task.wait(delayTime)
end
task.wait(TTime)
self.Object:Destroy()
end
return CraterGenerator
Again,
The goal of the first module function is to create rubble, the second (Which is the one I have problems with) is bugging out. Would appreciate any help