Can't tween BALLS

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!

if that is line 3, then I guess that it wants a string of charaters.

This might turn a number into a string:

Name = tostring(Name)

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.

it helps if u give the line number of the error

here, ur calling the Function waterball, but with 0 arguments.()

I’m thinking maybe you should go look-up some artical called, Programming 101…

Other references:

You need the wiki

Tween (roblox.com)

And you can do a search on the Lua Reference manual

That’s an unnecessary comment, try again.

Anyways for OP on your tween function send your waterball as first argument and use it that way

1 Like

I don’t know Roblox very well, so if I am catching the errors, then they are basic.

local function waterball(Color, Size, Reflectance, Material, Name)
	local water = Instance.new("Part")
	water.Name = "Water"
	water.Shape = Enum.PartType.Ball
	water.Color = Color3.new(0, 0, 1)
	water.Material = Enum.Material.Plastic
	water.Transparency = 0.4
	water.Anchored = false
	water.Reflectance = 0
	water.Size = Vector3.new(5, 5, 5)
	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

You just hadn’t correctly defined the properties of the water part being created.

I’m just starting out in scripting so I don’t know slot but try using some time scripts in it

It seems the tweening doesn’t work but it does delete the balls.

local Materials = {Enum.Material.Glass, Enum.Material.Foil, Enum.Material.Glacier, Enum.Material.Brick}
local function waterball()
	local water = Instance.new("Part")
	water.Name = "Water"
	water.Shape = Enum.PartType.Ball
	water.Color = Color3.fromRGB(math.random(30, 40), math.random(10, 20), math.random(145, 155))
	water.Material = Materials[math.random(#Materials)]
	water.Transparency = 0.4
	water.Anchored = false
	water.Reflectance = math.random(10,20)/10
	water.Size = Vector3.new(math.random(10,20)/100, math.random(300,400)/50, math.random(300,400)/50)
	water.CFrame = CFrame.new(34.928, 3.363, 4.785)
	water.Parent = workspace
    
	local TweenService = game:GetService("TweenService")
	local Tweeninfo = TweenInfo.new(
		1,
		Enum.EasingStyle.Linear,
		Enum.EasingDirection.In,
		0,
		false,
		0
	)
	local goal = {}
	goal.Transparency = 0

	local BallTween = TweenService:Create(water, Tweeninfo, goal)

    BallTween:Play()

    local Debris = game:GetService("Debris")

    Debris:AddItem(water,4)
end

for i = 1,100,.01 do  
	task.wait()
    waterball()
end
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

I tested the code and it works

1 Like