I can’t seem to figure out how to make a ball just tween to disappearance and then get destroyed.
It just says stack overflow and "ServerScriptService.Server:3: invalid argument #3 (string expected, got nil),
Here is the code:
local function waterball(Color, Size, Reflectance, Material, Name)
local water = Instance.new("Part")
water.Name = Name
water.Shape = Enum.PartType.Ball
water.Color = Color
water.Material = Material
water.Transparency = 0.4
water.Anchored = false
water.Reflectance = Reflectance
water.Size = Size
water.CFrame = CFrame.new(34.928, 3.363, 4.785)
water.Parent = workspace
return water
end
local function tween()
local water = waterball()
local TweenService = game:GetService("TweenService")
local Tweeninfo = TweenInfo.new(
1,
Enum.EasingStyle.Linear,
Enum.EasingDirection.In,
0,
false,
0
)
local goal = {}
goal = water.Transparency == 0
local Tween = TweenService:Create(water, Tweeninfo, goal)
Tween:Play()
Tween.Completed:Connect(function()
local Debris = game:GetService("Debris")
Debris:AddItem(water)
end)
end
local Materials = {Enum.Material.Glass, Enum.Material.Foil, Enum.Material.Glacier, Enum.Material.Brick}
for i = 1,1000,.01 do
task.wait()
waterball(Color3.fromRGB(math.random(30, 40), math.random(10, 20), math.random(145, 155)),--color
Vector3.new(math.random(10,20)/100,--size
math.random(300,400)/50,
math.random(300,400)/50),
math.random(10,20)/10,--reflectance
Materials[math.random(#Materials)]
)
tween()
end
I would also like some tips on how to make the script better AND what to do to make it work.
Any amount of help is very appreciated!
I actually fixed it to this but now it says color is nil. I think it will be one after another witch each one removed. There has to be a different way.
local TweenService = game:GetService("TweenService")
local Debris = game:GetService("Debris")
local Materials = {"Glass", "Foil", "Glacier", "Brick"}
local function Waterball()
local Water = Instance.new("Part")
Water.Name = "Water"
Water.Shape = Enum.PartType.Ball
Water.Material = Enum.Material[Materials[math.random(#Materials)]]
Water.Transparency = 0.4
Water.Anchored = false
Water.Reflectance = math.random(10, 20) / 10
Water.CFrame = CFrame.new(34.928, 3.363, 4.785)
Water.Size = Vector3.new(
math.random(10, 20) / 100,
math.random(300, 400) / 50,
math.random(300, 400) / 50
)
Water.Color = Color3.fromRGB(
math.random(30, 40),
math.random(10, 20),
math.random(145, 155)
)
Water.Parent = workspace
return water
end
local function TweenWater(Water, Time)
local Connection
local Tween = TweenService:Create(Water, TweenInfo.new(
Time,
Enum.EasingStyle.Linear,
Enum.EasingDirection.In
), {
Transparency = 1
}
)
Tween:Play()
Connection = Tween.Completed:Connect(function()
Debris:AddItem(Water)
Connection:Disconnect()
end)
end
for Count = 1, 100000, 1 do task.wait(0.05)
TweenWater(Waterball(), 1)
end
basically I made the code a bit better formatted, and I added improvements such as disconnecting the connection for the tween and removing the fractions in the for loop
I decided to remove the parameters inside the WaterBall() function and just set them as it’s default settings
the code is already a bit heavy on the game so I made it wait 0.05 seconds instead to slow a down a tiny bit