I’m making a merge-style game and basically when the player clicks and holds, it shows arrows relative to the hole they are on. Example:
https://i.gyazo.com/b0d8c710ffe18fdb6beb440849bbb9c5.mp4 (the video doesn’t embed for some reason)
So basically, as you can see when you click and hold on the gem it shows arrows, right? Then, when they click “UpArrow” (up), “LeftArrow” (left), “DownArrow”, (down), or “RightArrow” (right) it prints something which will later turn into merging.
It is supposedly supposed to work, but it never runs at all?
Here is my code:
Merge.lua (Localscript located in StarterPlayerScripts)
-- made by recanman
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local island = game.Workspace:WaitForChild("PlayerFolders"):WaitForChild(plr.Name).Island
local merge = require(game.ReplicatedStorage.Assets.Modules.MergeSystem)
local isDown = false
local currentHole = nil
mouse.Button1Down:Connect(function()
merge.Button1Down(mouse)
currentHole = merge:ReturnCurrentHoleAsString()
isDown = true
end)
mouse.Button1Up:Connect(function()
merge.Button1Up()
if (isDown == true) then
merge:DisconnectInput()
isDown = false
end
end)
game:GetService("UserInputService").InputBegan:Connect(function(input, gpe)
if (isDown == true and currentHole ~= nil and gpe ~= true) then
merge:TakeInput(currentHole, input)
end
end)
MergeSystem.lua (modulescript)
-- made by recanman
local merge = {}
local controls = require(game.ReplicatedStorage.Assets.Modules.Controls)
local t = {D = "D"}
local mtarget
local hasGui = false
local positions = {
UpArrow = UDim2.new(0.335, 0, 0, 0),
DownArrow = UDim2.new(0.335, 0, 0.67, 0),
LeftArrow = UDim2.new(0, 0, 0.335, 0),
RightArrow = UDim2.new(0.67, 0, 0.335, 0)
}
local connection = nil
local function initGem(hole, gem)
for name, _ in pairs(controls[hole.Name]) do
local clone = script.MainFrame:Clone()
clone.Name = name .. "Arrow"
clone.MainText.Text = script.Presets[clone.Name].Value
clone.Position = positions[clone.Name]
clone.Parent = gem.Core.HoverUI
end
gem.Core.HoverUI.Enabled = true
end
local function showControls(hole)
local gem = hole:FindFirstChildOfClass("Model")
initGem(hole, gem)
end
function merge.Button1Down(mouse)
if (mouse.Target ~= nil) then
if (string.lower(mouse.Target.Name) == "border" or string.lower(mouse.Target.Name) == "border") then
mtarget = mouse.Target
if (mouse.Target.Parent.Core.HoverUI:FindFirstChildOfClass("ImageLabel") ~= nil) then
hasGui = true
mouse.Target.Parent.Core.HoverUI.Enabled = true
elseif (mouse.Target.Parent.Core.HoverUI:FindFirstChildOfClass("ImageLabel") == nil) then
showControls(mtarget.Parent.Parent)
hasGui = true
end
end
end
end
function merge.Button1Up()
if (hasGui == true and mtarget ~= nil) then
hasGui = false
mtarget.Parent.Core.HoverUI.Enabled = false
end
end
function merge:TakeInput(hole)
connection = game:GetService("UserInputService").InputBegan:Connect(function(input, gpe)
print(string.sub(tostring(input.KeyCode), 14)) -- prints
for name, child in ipairs(t)do--controls[hole]) do
print(string.sub(tostring(input.KeyCode), 14)) -- doesnt print
if (string.sub(tostring(input.KeyCode), 14) == name) then
print("merge") -- doesn't print either
end
end
print(string.sub(tostring(input.KeyCode), 14)) -- prints
end)
end
function merge:DisconnectInput()
if (connection ~= nil) then
connection:Disconnect()
wait(0.2)
connection = nil
end
end
function merge:ReturnCurrentHoleAsString()
if (mtarget ~= nil) then
return mtarget.Parent.Parent.Name
else
return nil
end
end
return merge
Controls.lua (ModuleScript, later the trues will become Enum.KeyCodes for custom keybinds)
-- made by recanman
local controls = {}
controls.Hole1 = {
Down = true,
Left = true
} controls.Hole2 = {
Down = true,
Right = true,
Left = true
} controls.Hole3 = {
Down = true,
Right = true,
Left = true
} controls.Hole4 = {
Down = true,
Right = true
} controls.Hole5 = {
Up = true,
Left = true
} controls.Hole6 = {
Up = true,
Right = true
} controls.Hole7 = {
Up = true,
Right = true,
Left = true
} controls.Hole8 = {
Up = true,
Right = true,
Left = true
}
return controls
Any help would be appreciated. Thanks!