Local Script inside the Tool
local Player = game.Players.LocalPlayer
local mouse = Player:GetMouse()
local preview = false
local UIS = game:GetService("UserInputService")
local debounce = false
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.M then
script.Parent.Events.ChangeMode:FireServer()
elseif input.KeyCode == Enum.KeyCode.T then
if debounce == false then
debounce = true
script.Parent.Events.Build:FireServer(debounce)
elseif debounce == true then
debounce = false
script.Parent.Events.Build:FireServer(debounce)
end
end
end)
local equipped = false
function PreviewF(val)
local clone
if script.Parent.DigMode.Value ~= true and val ~= nil then
spawn(function()
print("this happens")
preview = true
clone = val:Clone()
clone.Parent = game.Workspace
clone:TranslateBy(mouse.Hit.p)
local rotation = CFrame.Angles(0, math.rad(Player.Character.HumanoidRootPart.Orientation.Y), 0)
local modelCFrame = clone:GetPrimaryPartCFrame()
clone:SetPrimaryPartCFrame( modelCFrame * rotation )
for i,v in pairs(clone:GetDescendants()) do
pcall(function()
v.Transparency = 0.5
v.CanColide = false
v.Anchored = true
end)
end
end)
elseif preview == true then
pcall(function()
clone:Destroy()
preview = false
end)
end
end
script.Parent.Equipped:Connect(function()
script.Parent.Events.ToolE:FireServer()
equipped = true
end)
script.Parent.Unequipped:Connect(function()
script.Parent.Events.ToolUnE:FireServer()
equipped = false
end)
mouse.Button1Down:Connect(function(opt)
if equipped == true then
script.Parent.Events.Dig:FireServer(mouse.Hit.p)
end
end)
wait(1)
script.Parent.Events.ChangedVal.OnClientEvent:Connect(function(gaming,gamingalso)
print(gaming)
end)
while wait(5) do
print(script.Parent.Selected.Value)
end
Script inside the GUI which gets inserted to PlayerGUI
local MF = game.ServerScriptService.Maginot.MaginotForts
local plr = script.Parent.Parent.Parent.Parent
print(plr)
local Fort = require(game.ServerScriptService.Maginot.Class.Fortification)
local types = {}
local forts = {}
local plrteam = MF:FindFirstChild(plr.Team.Name)
for c,x in pairs(plrteam:GetChildren()) do -- Puts everything in their tables and class
table.insert(types,x)
end
local function GetChildrenByType(obj,typeo)
local children = {}
for i,v in pairs(obj:GetChildren()) do
if v:IsA(typeo) then
table.insert(children,v)
end
end
return children
end
local function FortButton(fort)
print(fort)
local clone = script.Parent.ButtonStore.Button:Clone()
clone.Parent = script.Parent
clone.Text = fort.Name
script.Parent.UIGridLayout.HorizontalAlignment = Enum.HorizontalAlignment.Center
clone.Visible = true
clone.MouseButton1Down:Connect(function()
print(script.Parent.Parent.Tool.Value.Selected.Value)
script.Parent.Parent.Tool.Value.Selected.Value = fort
print(script.Parent.Parent.Tool.Value.Selected.Value)
end)
end
local function FolderButton(folder)
local clone = script.Parent.ButtonStore.Button:Clone()
clone.Parent = script.Parent
clone.Text = folder.Name
script.Parent.UIGridLayout.HorizontalAlignment = Enum.HorizontalAlignment.Center
clone.Visible = true
clone.MouseButton1Down:Connect(function()
for x,c in pairs(GetChildrenByType(script.Parent,"TextButton")) do
c:Destroy()
end
for x,c in pairs(folder:GetChildren()) do
FortButton(c)
end
end)
end
for i,v in pairs(types) do
FolderButton(v)
end
script.Parent.Parent.Back.MouseButton1Down:Connect(function()
for x,c in pairs(GetChildrenByType(script.Parent,"TextButton")) do
c:Destroy()
end
script.Parent.Visible = false
script.Parent.Parent.Back.Visible = false
end)
And the Script of the Tool
local ToolGui
local Digmode = script.Parent.DigMode.Value
local Maginot = game.ServerScriptService.Maginot
local Progressing = false
local anim
local PlacetoPlace
local Selected
local player
local function callback()
ToolGui.ProgressFrame.Visible = false
ToolGui.ProgressFrame.Progress.Size = UDim2.new(0,0,1,0)
Progressing = false
print(PlacetoPlace)
if Digmode == false and script.Parent.Selected.Value ~= nil then
local clone = script.Parent.Selected.Value:Clone()
clone.Parent = Maginot.Configuration.ParentFortsTo.Value
if script.Parent.Selected.Value.Configuration.Overlap.Value == true then
clone:TranslateBy(PlacetoPlace)
elseif script.Parent.Selected.Value.Configuration.Overlap.Value == false then
clone:MoveTo(PlacetoPlace)
end
local rotation = CFrame.Angles(0, math.rad(player.Character.HumanoidRootPart.Orientation.Y), 0)
local modelCFrame = clone:GetPrimaryPartCFrame()
clone:SetPrimaryPartCFrame( modelCFrame * rotation )
end
end
function ProgressIncrease(waittime)
ToolGui.ProgressFrame.Visible = true
ToolGui.ProgressFrame.Progress:TweenSize(
UDim2.new(1,0,1,0),
Enum.EasingDirection.Out, -- easingDirection (default Out)
Enum.EasingStyle.Quad, -- easingStyle (default Quad)
waittime, -- time (default: 1)
true, -- should this tween override ones in-progress? (default: false)
callback)
end
script.Parent.Events.ChangeMode.OnServerEvent:Connect(function()
if anim.IsPlaying then
callback()
end
if Digmode == nil then
Digmode = true
ToolGui.Mode.Text = "Mode: Dig"
else
Digmode = false
ToolGui.Mode.Text = "Mode: Build"
end
end)
script.Parent.Events.Dig.OnServerEvent:Connect(function(plr,position)
print('fired')
PlacetoPlace = position
anim = script.Parent.Parent.Humanoid:LoadAnimation(script.Parent.Anims.Dig)
Progressing = true
print(script.Parent.Selected.Value)
spawn(function()
while Progressing == true do
anim:Play()
wait(1)
end
end)
if Digmode == false then
if script.Parent.Selected.Value == false then
else
local Fort = require(game.ServerScriptService.Maginot.Class.Fortification)
Selected = Fort(script.Parent.Selected.Value)
ProgressIncrease(Selected.BuildTime)
end
elseif Digmode == true then
ProgressIncrease(Maginot.Configuration.DigTime.Value)
end
end)
script.Parent.Events.ToolE.OnServerEvent:Connect(function(plr)
ToolGui = script.Parent.ToolGui:Clone()
ToolGui.Tool.Value = script.Parent
ToolGui.Parent = plr.PlayerGui
end)
script.Parent.Events.Build.OnServerEvent:Connect((function(plr,debounce)
player = plr
if debounce == true then
ToolGui.Back.Visible = true
ToolGui.ScrollingFrame.Visible = true
ToolGui.ScrollingFrame.Setup.Disabled = false
elseif debounce == false then
ToolGui.Back.Visible = false
ToolGui.ScrollingFrame.Visible = false
end
end))
script.Parent.Events.ToolUnE.OnServerEvent:Connect(function(plr)
callback()
ToolGui:Destroy()
end)
script.Parent.Selected.Changed:Connect(function(val)
print(val)
script.Parent.Events.ChangedVal:FireAllClients(val)
end)