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

How do I use tweening?

I'm working on a inventory system, but I don't like it just appearing, it looks ugly, So I want it to kind of, smoothly come out of the center, but it isn't working for me, The box doesn't appear when I test it Here's my code inside the frame:

CAS = game:GetService('ContextActionService')
function OpenInv(actionName, userInputState, inputObject)
	if userInputState == Enum.UserInputState.Begin then
		
		print('Open Inventory')
		script.Parent.Visible = true
		script.Parent.Position = UDim2.new(0.5, 0, 0.5, 0) -- We set the scales to .5, .5, which is the center of the screen
		script.Parent.Size = UDim2.new(0,0,0,0) -- We set the frame size to 0, so it will pop out of the middle of the screen.  
		script.Parent:TweenSizeAndPosition(UDim2.new(0, 400, 0, 600), UDim2.new(.5, -200, .5, 600), "Out", "Quad", 1) -- This will change the size, from 0,0 to 400, 600, and the position will change so the frame stays centered.
	end
end
function CloseInv(actionName, userInputState, inputObject)
	if userInputState == Enum.UserInputState.Begin then
		
		print('Close Inventory')
		--i also want to use tweening here to make it smoothly go in
		script.Parent.Visible = false
		
	end
end
CAS:BindAction("invClose", CloseInv, false, Enum.KeyCode.R) 
CAS:BindAction("invOpen", OpenInv, false, Enum.KeyCode.E) 

1 answer

✓ Accepted answer
CAS = game:GetService('ContextActionService')
function OpenInv(actionName, userInputState, inputObject)
    if userInputState == Enum.UserInputState.Begin then

        print('Open Inventory')
        script.Parent.Visible = true
        script.Parent.Position = UDim2.new(0.5, 0, 0.5, 0) -- We set the scales to .5, .5, which is the center of the screen
        script.Parent.Size = UDim2.new(0,0,0,0) -- We set the frame size to 0, so it will pop out of the middle of the screen.  
        script.Parent:TweenSizeAndPosition(UDim2.new(0, 400, 0, 600), UDim2.new(.5, -200, .5, -300), "Out", "Quad", 1, true) -- This will change the size, from 0,0 to 400, 600, and the position will change so the frame stays centered.
    end
end
function CloseInv(actionName, userInputState, inputObject)
    if userInputState == Enum.UserInputState.Begin then

        print('Close Inventory')
        --i also want to use tweening here to make it smoothly go in
	script.Parent:TweenSizeAndPosition(UDim2.new(0, 0, 0, 0), UDim2.new(0.5, 0, 0.5, 0), "Out", "Quad", 1, true)
	wait(1)
	if (script.Parent.Size == UDim2.new(0, 0, 0, 0)) then
       	 script.Parent.Visible = false
	end
    end
end
CAS:BindAction("invClose", CloseInv, false, Enum.KeyCode.R) 
CAS:BindAction("invOpen", OpenInv, false, Enum.KeyCode.E) 

That should work better.

1 comment

0

Thanks i'll try it

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