Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

TweenSize() Callback executing early?

When this code executes, the function CallMine() is supposed to be called once the Tween is finished. However, the CallMine() code executes as soon as I click. Any idea as to why?

Mouse.Button1Down:Connect(function() 

	

	Button1Down = true	
	
	if Equipped then
		if Mouse.Target ~= nil and Mouse.Target:IsDescendantOf(workspace.Mine) then
			
			block = Mouse.Target			
			
			mining = true
			
			while mining == true and block == block do
				
				
				ProgressBar:TweenSize(UDim2.new(0.96, 0, 0.7, 0), "InOut", "Sine", MineTime, false, function() CallMine(block.Parent) end )
				
				mining = false
				
				
			end
			
			
			
			
		end
	end	
	
	
end)

function CallMine(block)
	
	print(block)
	BlockEvent:FireServer(block) -- block.Parent is the model, and block is the PrimaryPart.
		
end

1 answer

✓ Accepted answer

Do not put strings where Enum's are supposed to go, Here's your code, rewritten. Make sure it's a Local Script.

mouse.Button1Down:Connect(function()
    mouseDown = true
    mining = true
    if equipped then
        if mouse.Target ~= nil and mouse.Target:IsDescendantOf(game.Workspace.Mine) then
            block = mouse.Target -- Declared global.
            while mining do
                wait(someTime) -- Specify your time here. Wait functions are mandatory in any loop. A repeat until loop, a for loop, While loops. 
                bar:TweenSize(UDim2.new(0.96,0,0.7,0), Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, mineTime, callMine) -- You don't include the () in the function. Unfortunately, arguments can't be passed. Instead of using "block" as a parameter, just use the actual block itself. 
            end
        end
    end
end)

function callMine() -- Do not provide parameters.
    print(block)
    blockEvent:FireServer(block) -- Since the block variable in the Button 1 down event was declared global, it can be used here.
end

1 comment

1

thanks for the in depth explanation. This is much more efficient (and works!) much appreciated!

This discussion is preserved as it was. New answers, comments, and votes are closed.