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)
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()
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.
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)