So I’m currently making a merge-style game, similar to Merge Gems.
Instead of clicking and dragging, I want a ui to show that are arrows (already achieved).
It duplicates so much and instead of it deleting itself when the mouse moves it makes more!
I’ve tried multiple different solutions but i’m stumped. Nothing found on dev hub.
Here is my code:
Merge (localscript)
-- 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 mtarget
local db = false
local hasGui = false
mouse.Move:Connect(function()
if (db == true) then wait() else
db = true
if (mouse.Target ~= nil) then
if (string.lower(mouse.Target.Name) == "border") then
mtarget = mouse.Target
merge.ShowControls(mtarget.Parent.Parent)
hasGui = true
if (hasGui == true and mtarget ~= nil) then
mtarget.Parent.Core:FindFirstChildOfClass("BillboardGui"):Destroy()
hasGui = false
wait()
end
end
end
wait(0.1)
db = false
end
end)
MergeSystem (modulescript)
-- made by recanman
local merge = {}
local controls = require(script.Controls)
local function showHoverUi(preset, gem)
local hoverUi = game.ReplicatedStorage.Assets.UI.HoverUI:Clone()
hoverUi.Parent = gem.Core
hoverUi.MainFrame.MainText.Text = hoverUi.Presets[preset].Value
if (preset == "UpArrow") then hoverUi.ExtentsOffset = Vector3.new(0, 2.5, 0)
elseif (preset == "DownArrow") then hoverUi.ExtentsOffset = Vector3.new(0, -2.5, 0)
elseif (preset == "LeftArrow") then hoverUi.ExtentsOffset = Vector3.new(-2.5, 0, 0)
elseif (preset == "RightArrow") then hoverUi.ExtentsOffset = Vector3.new(2.5, 0, 0)
else print("Malformed preset.") end
end
function merge.ShowControls(hole)
local ui = game.ReplicatedStorage.Assets.UI.HoverUI
local gem = hole:FindFirstChildOfClass("Model")
for name, _ in pairs(controls[hole.Name]) do
showHoverUi(name .. "Arrow", gem)
end
end
return merge
Controls (modulescript)
-- 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
My problem is that it creates multiple HoverUI’s and when I move the mouse away it stays there and creates multiple.
https://i.gyazo.com/c81b39216fb3cc652cebc6613e3e1c30.mp4
How would I make it so it would make 1 copy of the HoverUI, then when I hover away it destroys itself?
Any help would be appreciated, thanks!
