MouseHoverEnter- and MouseHoverLeave not working

Hello.

I am trying to make a system that displays a screengui that is inside startergui, whenever your mouse hovers over “CDPart”, it would make a screengui visible.

Here is my code.

repeat wait(3) until game:IsLoaded()

local clickDetector = script.Parent:FindFirstChildOfClass("ClickDetector")
local CDpart = script.Parent

clickDetector.MouseHoverEnter:Connect(function(player)
	print("Test")
end)

clickDetector.MouseHoverLeave:Connect(function(player)
	print("Test")
end)

I suspect the code is not the problem, as nothing is wrong in input.

This is the layout in my workspace:
image

You can’t use local scripts in the workspace!

1 Like

Shoot you’re right, I didn’t know this.

Thank you, it works now!

1 Like

By the way, do you happen to know if Screenguis can be changed from the workspace?

What do you mean by this?

Technically, screenGuis can be changed from anywhere. And to the original post you could use the local script, you just needed to copy-paste the code into a server script, and then set the Script.RunContext to Client

Hey.

I did that, I copied the localscript and pasted into s-script, changed runcontext into client and the prints work.

The problem is that for some reason, the screengui located in startergui is not changing.

Here is my current code:

repeat wait(1) until game:IsLoaded()

local clickDetector = script.Parent
local CDpart = script.Parent.Parent
local Startergui = game:FindFirstChild("StarterGui")

local CDGui = Startergui.ClickDetector.Frame.TextLabel.Text

clickDetector.MouseHoverEnter:Connect(function(player)
	print("touching")
	CDGui = "Insert tape"
end)

clickDetector.MouseHoverLeave:Connect(function(player)
	print("nottouching")
	CDGui = " "
end)

Because gui that players see differ from what is in StarterGui.

You see, StarterGui contains original ScreenGui

To get the actual player gui, you have to use this method:

local Players = game:GetService('Players')
local localPlr = Players.LocalPlayer
local plrGui = localPlr:WaitForChild('PlayerGui')

PlayerGui is basically a clone of StarterGui, the difference being that it’s what players actually see. The rest is the same

Oh shoot I remember having this problem.

This came to my mind but I didn’t quite remember.

Thank you for the help, i’ll mark this as the solution if this works.

Still nothing.

Here is the new code:

repeat wait(1) until game:IsLoaded()

local plr = game.Players.LocalPlayer
local plrGui = plr:WaitForChild('PlayerGui')

wait(1)

local clickDetector = script.Parent
local CDpart = script.Parent.Parent

local CDGui = plrGui.ClickDetector.Frame.TextLabel
local text = CDGui.Text

clickDetector.MouseHoverEnter:Connect(function(player)
	print("touching")
	CDGui = "Insert tape"
end)

clickDetector.MouseHoverLeave:Connect(function(player)
	print("nottouching")
	CDGui = " "
end)

I think you forgot to put .Text when changing text

I didn’t notice that. I changed it, but still nothing.

This is very strange.

Where exactly did you put the local script now

Are you using text variable that you defined after CDGui? Changing text will have no effect

Right now it is in CDPart.

This is the current script

repeat wait(1) until game:IsLoaded()

local plr = game.Players.LocalPlayer
local plrGui = plr:WaitForChild('PlayerGui')

wait(1)

local clickDetector = script.Parent.ClickDetector
local CDpart = script.Parent

local CDGui = plrGui.ClickDetector.Frame.TextLabel
local text = CDGui.Text

clickDetector.MouseHoverEnter:Connect(function(player)
	print("touching")
	text = "Insert tape"
end)

clickDetector.MouseHoverLeave:Connect(function(player)
	print("nottouching")
	text = " "
end)

I got it to work now, I removed the “text” variable and just went with CDGui.Text = " "

Replace text with CDGui.Text

text is a copy of a CFGui.Text value, which means changing either of these will not change the other one’s value

That is right, i’ll mark this as solution.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.