Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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.

1 comment

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

3 answers

✓ Accepted answer

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

1 comment

0

:connect requires a function, you are running the function. remove the ()

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)

3 comments

0

All this does it set a variable "on" to true of false you have not used the value set????

0

This answer doesnt explain anything.

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.

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)

1 comment

0

And how is wait() supposed to help.

This discussion is preserved as it was. New answers, comments, and votes are closed.