Im making a script that charges up an orb, the orb uses a tweening animation to grow as it charges, however I was unable to figure out why it wasn't tweening. It might have something to do with where I put it. Can someone help me figure out how? Tween:

local tween = game:GetService("TweenService")
	local tweenInfo = TweenInfo.new(1,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0)
	local tweenProperty = {Size = Vector3.new(1,1,1)}
	local tweenRun = tween:Create(charging, tweenInfo,tweenProperty)
	tweenRun:Play()

Main script:

game.ReplicatedStorage.Custom.OnServerEvent:Connect(function(plr,mousehit,key)
	if key == "Cero2" then
		local char = game.Players[plr.Name].Character
		local hum = char.Humanoid
        local root = char.HumanoidRootPart
        local charging = Instance.new("Part")
        charging.Shape = Enum.PartType.Ball
        charging.Material = Enum.Material.Neon
        charging.Size = Vector3.new(0.1,0.1,0.1)
        charging.BrickColor = BrickColor.new("Really red")
        charging.CanCollide = false
        charging.Parent = workspace
    
	local weld = Instance.new("Weld")
	charging.CFrame = char.Head.CFrame * CFrame.new(0,0,-2)
	weld.Part0 = char.Head
	weld.Part1 = charging
	weld.C0 = char.Head.CFrame:Inverse()
	weld.C1 = charging.CFrame:Inverse()
	weld.Parent = charging
	
	function charge()
		local chargingPart = charging:Clone()
		chargingPart.Parent = charging
		chargingPart.CanCollide = false
	    chargingPart.Shape = Enum.PartType.Ball
        chargingPart.Material = Enum.Material.Neon
        chargingPart.BrickColor = BrickColor.new("Really red")
        chargingPart.Size = Vector3.new(0.1,0.4,0.1)
        chargingPart.CFrame = charging.CFrame * CFrame.new(math.random(-0.6,0.6),math.random(-0.6,0.6),math.random(-0.6,0.6))
        chargingPart.Parent = charging
        chargingPart.Anchored = true
        game.Debris:AddItem(chargingPart,0.01)
	end
	
	    for i = 1,100 do
		spawn(charge)
		wait(0.01)
	end
	end
end)

1 comment

0

I believe the charge function should be a local function (e.g. 'local function charge()' instead of 'function charge()') since it is inside another function.