Hi, I was writing a shop GUI and got stuck with some problems.
function showInfo(Weapon)
--//Ran Variables
local StatsFolder = Weapon:FindFirstChild("Stats")
local AccuracyV = StatsFolder:FindFirstChild("Accuracy").Value
local AmmoV = StatsFolder:FindFirstChild("Ammo").Value
local DamageV = StatsFolder:FindFirstChild("Damage").Value
local FireRateV = StatsFolder:FindFirstChild("FireRate").Value
InfoFrame.Accuracy.Text = "Accuracy: "..AccuracyV
InfoFrame.Ammo.Text = "Ammo: "..AmmoV
InfoFrame.Damage.Text = "Damage: "..DamageV
InfoFrame.FireRate.Text = "FireRate: "..FireRateV
InfoFrame.Visible = true
InteractButton.MouseButton1Click:Connect(function()
ShopRemote:FireServer(Weapon)
end)
end
local function hideInfo()
InfoFrame.Visible = false
end
for i, v in pairs(BothFrame:GetChildren()) do
if v:IsA("ViewportFrame") then
--//WhenEnterAndLeave
v.MouseEnter:Connect(function()
print(v)
showInfo(v)
end)
v.MouseLeave:Connect(function()
print(v)
end)
end
end
So the problem is, the event saves how many times the mouse has entered the viewportframe.
So if you enter your mouse in scar’s portframe 3 times, it would fire 3 times etc. https://gyazo.com/741566503da452288a0b38f3554747e6
as you can see, how many times it prints on the server is depending on how many times the mouse enter on client.
I know this problem is probably very easy to solve, but I can’t.
I’m not sure what the problem here is. Are you wanting it to where the remote only fires for the first time you hover your mouse over a weapon’s UI frame? And not firing for each subsequent hover-over.
This should work. All we do is create a table on the client, and whenever the mouse enters the frame, it checks if the table has an entry for that frame. If not, it creates an entry and runs showInfo. If it does have an entry, it doesn’t do anything. Technically you could just have the script disconnect the MouseEnter connection after the first time it runs but that’s a little bit more work.
function showInfo(Weapon)
--//Ran Variables
local StatsFolder = Weapon:FindFirstChild("Stats")
local AccuracyV = StatsFolder:FindFirstChild("Accuracy").Value
local AmmoV = StatsFolder:FindFirstChild("Ammo").Value
local DamageV = StatsFolder:FindFirstChild("Damage").Value
local FireRateV = StatsFolder:FindFirstChild("FireRate").Value
InfoFrame.Accuracy.Text = "Accuracy: "..AccuracyV
InfoFrame.Ammo.Text = "Ammo: "..AmmoV
InfoFrame.Damage.Text = "Damage: "..DamageV
InfoFrame.FireRate.Text = "FireRate: "..FireRateV
InfoFrame.Visible = true
InteractButton.MouseButton1Click:Connect(function()
ShopRemote:FireServer(Weapon)
end)
end
local function hideInfo()
InfoFrame.Visible = false
end
local Frames = {}
for i, v in pairs(BothFrame:GetChildren()) do
if v:IsA("ViewportFrame") then
--//WhenEnterAndLeave
v.MouseEnter:Connect(function()
print(v)
if not Frames[v] then
Frames[v] = true
showInfo(v)
end
end)
v.MouseLeave:Connect(function()
print(v)
end)
end
end
Ohh, I see what you mean, what is the way to fix that? I was originally gonna make viewportframe click, but then I realised there is no click event for it.
The script you modified fixed the one time issue. The problem still occurs when the mouse enters the different weapon for example if it enters scars twice, it only prints scar once. But if it enters scar and other weapon for example m1014, it prints both of them which means it still fires both.
Guys, I fixed it. The problem was actually with the mouseenter event it self. It’s pretty scuffed, so I ended up making an invisible button like he said, everything is fixed now.