How can I stop a return variable from firing the function?

Is there any way to stop the se(plr) function in my code from firing and making it so that it just checks if the tween is finished?

local function st(plr, mouse)
	local pTween = se(plr)
	
	pTween.Completed:Wait()
	
	local folder = workspace:WaitForChild(plr.Name.."sb")
	local part = folder:WaitForChild("Part")
	
	
	local partGoal = {}
	partGoal.Position = mouse 
	local pInfo = TweenInfo.new(1, Enum.EasingStyle.Linear)
	local partTween = ts:Create(part, pInfo, partGoal)
	partTween:Play()
	
	part.Touched:Connect(function(hit)
		if hit ~= nil then
			if hit:IsA("BasePart") or hit:IsA("Model") then
				folder:Destroy()
			end
		end
	end)
	
	debris:AddItem(folder, 6)
end

This will probably require you to edit something in the se() function. Is it possible you could show us what that se() function is at full?

This is what I have in my se() function:

local function se(plr)
	local char = plr.Character
	local hum = char:WaitForChild("Humanoid")
	local humrp = char:WaitForChild("HumanoidRootPart")
	
	
	local folder = Instance.new("Folder", workspace)
	folder.Name = plr.Name.."Spirit Bomb"
	
	local part = Instance.new("Part", folder)
	part.Shape = "Ball"
	part.Material = Enum.Material.Neon
	part.BrickColor = BrickColor.new("Electric blue")
	part.Size = Vector3.new(0.05,0.05,0.05)
	part.Anchored = true
	part.CanCollide = false
	part.CFrame = humrp.CFrame * CFrame.new(0, 20, 0)
	
	local goal = {}
	goal.Size = Vector3.new(19.95, 19.95, 19.95)
	local pInfo = TweenInfo.new(3,Enum.EasingStyle.Sine)
	local pTween = ts:Create(part, pInfo, goal)
	pTween:Play()
	
	return pTween
end

Well, since the function creates the tween and plays the tween, I don’t see how you expect the tween to finish if it isn’t ‘fired’ to begin with.

	local pTween = se(plr)    --this line fires the se() function which creates the tween and plays it and returns it, gets assigned to pTween
	
	pTween.Completed:Wait()  --this line waits for the tween to finish playing
1 Like

That’s exactly what I was going to say.

@Amran421 could you maybe specify the reason why you don’t what the pTween to be returned from the se function?

I am trying to make a attack were a ball expands in size above you and when you release the “m” key on the keyboard the ball will get thrown to the mouse position, but the ball increases in size and gets thrown when the “m” key is released.

So, just to be clear, you do NOT want the size to increase when the user presses M?

No, I want the size to increase when the user is holding down the M key, but when the user lets go the ball gets thrown.

Thank you for your help, I found out what I needed to do. I needed to find another way to detect when the tween finished rather than returning the function.

1 Like