Created
February 7, 2022 14:50
-
-
Save RobertCodez/2792534ac830c1ef5edcf13c21434fc2 to your computer and use it in GitHub Desktop.
A tool lodout for when the player joins
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local ToolFolder = game.ReplicatedStorage.Tools | |
local Template = script.Template | |
local player = game.Players.LocalPlayer | |
local PageIndex = 1 | |
local Pages = { | |
[1] = "Primary", | |
[2] = "Secondary", | |
[3] = "Melee", | |
[4] = "Misc" | |
} | |
local function AddObjects(Category) | |
local Folder = ToolFolder:FindFirstChild(Category) | |
if not Folder then return end | |
for _,item in pairs(script.Parent.ToolViewer.Holder:GetChildren()) do | |
if not item:IsA("UIGridLayout") then item:Destroy() end | |
end | |
for i,v in pairs(Folder:GetChildren()) do | |
local TemplateClone = Template:Clone() | |
TemplateClone.MouseEnter:Connect(function() | |
TemplateClone.ImageColor3 = Color3.new(0.254902, 0.254902, 0.254902) | |
script["UI Hover"]:Play() | |
end) | |
TemplateClone.MouseLeave:Connect(function() | |
TemplateClone.ImageColor3 = Color3.new(0.0941176, 0.0941176, 0.0941176) | |
end) | |
TemplateClone.MouseButton1Click:Connect(function() | |
script["UI Click"]:Play() | |
end) | |
TemplateClone.Title.Text = v.Name | |
TemplateClone.Parent = script.Parent.ToolViewer.Holder | |
end | |
end | |
local function UpdateViewer() | |
for i,v in pairs(script.Parent.ToolViewer.Holder:GetChildren()) do | |
if v:IsA('ImageButton') then | |
v.MouseButton1Click:Connect(function() | |
local Folder = ToolFolder:FindFirstChild(Pages[PageIndex]) | |
local Tool = Folder:FindFirstChild(v.Title.Text) | |
local Page = script.Parent.Viewer:FindFirstChild(Pages[PageIndex]) | |
Page.ToolName.Text = Tool.Name | |
end) | |
end | |
end | |
end | |
local function UpdateHolder() | |
script.Parent.MainBackground.ObjectType.Title.Text = Pages[PageIndex] | |
AddObjects(Pages[PageIndex]) | |
script.Parent.Navigation.Text = tostring(PageIndex).."/4" | |
UpdateViewer() | |
end | |
UpdateHolder() | |
script.Parent.Navigation.Front.MouseButton1Click:Connect(function() | |
script["UI Click"]:Play() | |
if PageIndex < 4 then | |
PageIndex += 1 | |
else | |
PageIndex = 1 | |
end | |
UpdateHolder() | |
end) | |
script.Parent.Navigation.Back.MouseButton1Click:Connect(function() | |
script["UI Click"]:Play() | |
if PageIndex > 1 then | |
PageIndex -= 1 | |
else | |
PageIndex = 4 | |
end | |
UpdateHolder() | |
end) | |
for i,v in pairs(script.Parent.Viewer:GetChildren()) do | |
v.Button.MouseButton1Click:Connect(function() | |
local PageNumber = v.PageNumber.Value | |
PageIndex = PageNumber | |
UpdateHolder() | |
end) | |
end | |
script.Parent.Navigation.Finish.MouseEnter:Connect(function() | |
script["UI Hover"]:Play() | |
end) | |
script.Parent.Navigation.Front.MouseEnter:Connect(function() | |
script["UI Hover"]:Play() | |
end) | |
script.Parent.Navigation.Back.MouseEnter:Connect(function() | |
script["UI Hover"]:Play() | |
end) | |
script.Parent.Navigation.Finish.MouseButton1Click:Connect(function() | |
script["UI Click"]:Play() | |
for i,v in pairs(script.Parent.Viewer:GetChildren()) do | |
if v.ToolName.Text ~= "None" then | |
local Category = v.Name | |
local Folder = ToolFolder:FindFirstChild(Category) | |
local Tool = Folder:FindFirstChild(v.ToolName.Text) | |
game.ReplicatedStorage.AddTool:FireServer(Tool) | |
end | |
end | |
script.Parent.Visible = false | |
end) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment