Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

This loop goes more than once, how do i fix that?

Asked by
Foridex 46
7 years ago
Edited 7 years ago

So this script makes the cursor (on hover) show a gui displaying the name of the item next to the cursor.

For some reason, every time i move the cursor just a little on the brick again, it will do the fading process AGAIN.

repeat wait() until game:GetService("Players").LocalPlayer
local found = game.Players.LocalPlayer:FindFirstChild("PlayerGui")
local gui = found:FindFirstChild("HoverGui")

game.Workspace.hover.ClickDetector.MouseHoverEnter:connect(function()
    gui.HoverFrame.Label.Text = "Brick"
    for i=1,0,-0.05 do
        gui.HoverFrame.Label.TextTransparency = i
        gui.HoverFrame.Label.BackgroundTransparency = i
        wait()
    end
    script.Disabled = true
end)

game.Workspace.hover.ClickDetector.MouseHoverLeave:connect(function()
    for i=0,1,0.05 do
        gui.HoverFrame.Label.TextTransparency = i
        gui.HoverFrame.Label.BackgroundTransparency = i
        wait()
    end
end)

I want the fading process to happen once only and it can be activated again after the mouse leaves from the brick.

0
You simply can't use script.Disabled because it is a bit buggish and it keeps events. Add a variable, "local work = true". replace script.Disabled with "work = false", and then add an if statement to HoverEnter/HoverLeave to make sure work == true before running luadotorg 194 — 7y

3 answers

Log in to vote
0
Answered by
Vezious 310 Moderation Voter
7 years ago
Edited 7 years ago

Here is another method:

repeat wait() until game:GetService("Players").LocalPlayer
local found = game.Players.LocalPlayer:FindFirstChild("PlayerGui")
local gui = found:FindFirstChild("HoverGui")


local MouseHoverEnterEvent

function MouseIn()
    MouseHoverEnterEvent:Disconnect() -- Disconnects the Event, so MouseHoverEnter won't be activated unless it's reconnected.
    gui.HoverFrame.Label.Text = "Brick"
    for i=1,0,-0.05 do
        gui.HoverFrame.Label.TextTransparency = i
        gui.HoverFrame.Label.BackgroundTransparency = i
        wait()
    end
end

game.Workspace.hover.ClickDetector.MouseHoverLeave:connect(function()
    for i=0,1,0.05 do
        gui.HoverFrame.Label.TextTransparency = i
        gui.HoverFrame.Label.BackgroundTransparency = i
        wait()
    end
    MouseHoverEnterEvent = game.Workspace.hover.ClickDetector.MouseHoverEnter:connect(MouseIn())-- Reconnects the MouseHoverEnter
end)

MouseHoverEnterEvent = game.Workspace.hover.ClickDetector.MouseHoverEnter:connect(MouseIn()) -- Makes the initial connection with MouseHoverEnter

0
:connect requires a function, you are running the function. remove the () User#5423 17 — 7y
Ad
Log in to vote
0
Answered by
FazNook 61
7 years ago

There is no requirement to disable the script unless your trying to do something else. What you needed was debounce. The script below is ready to use, please let me know if this answers your question.

repeat wait() until game:GetService("Players").LocalPlayer
local found = game.Players.LocalPlayer:FindFirstChild("PlayerGui")
local gui = found:FindFirstChild("HoverGui")
on = false

game.Workspace.hover.ClickDetector.MouseHoverEnter:connect(function()
    gui.HoverFrame.Label.Text = "Brick"
    for i=1,0,-0.05 do
        gui.HoverFrame.Label.TextTransparency = i
        gui.HoverFrame.Label.BackgroundTransparency = i
        on = true
        wait()
    end
end)

game.Workspace.hover.ClickDetector.MouseHoverLeave:connect(function()
    for i=0,1,0.05 do
        on = false
        gui.HoverFrame.Label.TextTransparency = i
        gui.HoverFrame.Label.BackgroundTransparency = i
        wait()
    end
end)
0
All this does it set a variable "on" to true of false you have not used the value set???? User#5423 17 — 7y
0
This answer doesnt explain anything. H4X0MSYT 536 — 7y
0
Yes, that is all that the script needed. I’ve tested this script and it works fine. Try it out and see it for yourself. FazNook 61 — 7y
Log in to vote
0
Answered by 7 years ago

try this

repeat wait() until game:GetService("Players").LocalPlayer
local found = game.Players.LocalPlayer:FindFirstChild("PlayerGui")
local gui = found:FindFirstChild("HoverGui")

game.Workspace.hover.ClickDetector.MouseHoverEnter:connect(function()
    gui.HoverFrame.Label.Text = "Brick"
    for i=1,0,-0.05 do
        gui.HoverFrame.Label.TextTransparency = i
        gui.HoverFrame.Label.BackgroundTransparency = i
        wait(9999999999999999999999)
    end
    script.Disabled = true
end)

game.Workspace.hover.ClickDetector.MouseHoverLeave:connect(function()
    for i=0,1,0.05 do
        gui.HoverFrame.Label.TextTransparency = i
        gui.HoverFrame.Label.BackgroundTransparency = i
        wait(9999999999999999999999)
    end
end)
0
And how is wait() supposed to help. FazNook 61 — 7y

Answer this question