Why is Gui not tweening position?

So i was testing out tweens and positions and I used userinputservice so when I press Tab the Gui will tween to the side. But when I press Tab nothing happens. What is the problem?


local UserinputService = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Character = Player.Character if not Character then return end
local Humanoid = Character:WaitForChild("Humanoid")
local Inventory = game:WaitForChild("PlayerGui"):WaitForChild("ScreenGui").MainFrame


UserinputService.InputBegan:Connect(function(input, IsTyping)
	
	if IsTyping then return end
	
	if input.KeyCode == Enum.KeyCode.Tab then
		
		for i,inventoryTable in pairs(Inventory:GetChildren()) do
			spawn(function()
				game:GetService("TweenService"):Create(inventoryTable, TweenInfo.new(2), {Postion = UDim2.new(0.018, 0,0.237, 0)}):Play()

			end)
		end
	end
end)


UserinputService.InputEnded:Connect(function(input, IsTyping)
	
	if IsTyping then return end
	
	if input.KeyCode == Enum.KeyCode.Tab then

		for i,inventoryTable2 in pairs(Inventory:GetChildren()) do
			spawn(function()
				game:GetService("TweenService"):Create(inventoryTable2, TweenInfo.new(2), {Postion = UDim2.new(0.018, -600,0.237, 0)}):Play()

			end)
		end
	end
end)

image

1 Like

line 3: you have local Character = Player.Character if not Character then return end

this script is in starterplayerscripts (for a gui script???) which menas it will run BEFORE the characte lr has loaded so the script will never fully run

fix this by either moving it to the actual gui and getting rid of the local character since i dont see you using it anywhere
or just remove the character
or do

local Character = Player.Character or Player.CharacterAdded:Wait()

Its still not working do I change where I put my local script?

it inf waits for

local Inventory =  game:WaitForChild("PlayerGui"):WaitForChild("ScreenGui").MainFrame

because that doesn’t exist

you might be trying to do

local Inventory =  Player:WaitForChild("PlayerGui"):WaitForChild("Inventory").MainFrame

Tip: Always make sure to check the output, and put that in the post to help people help you

Okay I did what you told me but i got an error.
image

My frame gui has many different frames and labels inside of it.

you misspelt position. it says “Postion”

Oh i didn’t see that, but still nothing happens when I press the keycode /:

Where do i put the local script exactly??

I think the issue is with
local Inventory = game:WaitForChild(“PlayerGui”):WaitForChild(“ScreenGui”).MainFrame
Im pretty sure you cant have a WaitForChild connected to a WaitForChild
Try doing this:

local Inventory = game:WaitForChild("PlayerGui")
Inventory = Inventory:WaitForChild("ScreenGui").MainFrame

If that doesnt work, try to run a bunch of prints across the script and see if they all execute.

I just realized, game:WaitForChild() lol thats probably the issue

its game.Players.LocalPlayer:WaitForChild(“PlayerGui”)

wait isn’t it the same thing? I thought I already defined the player

You are trying to access the players gui of the whole explorer, the gui is located inside your player

Players > LocalPlayer > PlayerGui > GuiName
game.Players.LocalPlayer.PlayerGui:WaitForChild(‘Gui Name’)

Okay so i fixed that up but the script still isn’t working when I press F


local UserinputService = game:GetService("UserInputService")
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Inventory = game.Players.LocalPlayer.PlayerGui:WaitForChild("Inventory"):WaitForChild("MainFrame")

UserinputService.InputBegan:Connect(function(input, IsTyping)
	
	if IsTyping then return end
	
	if input.KeyCode == Enum.KeyCode.F then
	print("F printed")
		for i,inventoryTable in pairs(Inventory:GetChildren()) do
		
			local tweenCreate =	game:GetService("TweenService"):Create(inventoryTable, TweenInfo.new(2), {Position = UDim2.new(0.018, 0,0.237, 0)})
	
			tweenCreate:Play()
		end
	end
end)

image

Mayby thats because you are not checking if “inventoryTable” is a gui object.

You misspelt position

Edit: nvm you fixed that

I fixed it. Dont worry about it it was the table thingy

Starter GUI and you can do script. Blah blah because it gets copies into plrgui.