Hi, im first time trying to make inventory system.
I struggling how to make function to swap slots.
Any ideas how to make it?
Video how inventory works
Script inside ViewportFrame
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Main = script.Parent
local UiDrag = Main.UiDrag
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid",5)
local Mouse = Player:GetMouse()
local MainInventoryFrame = Main.Parent.Parent.Parent.Parent
local ParentFrame = Main.Parent
local IsMovingSomething = MainInventoryFrame.Parent.Info:WaitForChild("IsMovingSomething")
print(MainInventoryFrame)
local IsMovingrn = false
UiDrag.DragStart:Connect(function()
IsMovingrn = true
IsMovingSomething.Value = true
end)
UiDrag.DragEnd:Connect(function()
IsMovingrn = false
IsMovingSomething.Value = false
Main.Parent = ParentFrame
Main.Position = UDim2.new(0, 0, 0, 0)
end)
Main.MouseEnter:Connect(function()
if IsMovingSomething.Value == false then
local AbsolutePosition = Main.AbsolutePosition
Main.Parent = MainInventoryFrame
local newX = AbsolutePosition.X - MainInventoryFrame.AbsolutePosition.X
local newY = AbsolutePosition.Y - MainInventoryFrame.AbsolutePosition.Y
Main.Position = UDim2.new(0, newX, 0, newY)
end
end)
Main.MouseLeave:Connect(function()
if IsMovingrn == false then
Main.Parent = ParentFrame
Main.Position = UDim2.new(0, 0, 0, 0)
end
end)