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

Why doesn't my MouseHoverEnter event work in a local script?

I have a simple script:

local cd = script.Parent.ClickDetector

cd.MouseHoverEnter:Connect(function(plr)
	script.Parent:Destroy()
end)

It's in a local script because I plan on making do some other stuff later which I only want on the client. The script works fine when I put it in a regular script, but it doesn't work in a local script. Why?

1 answer

✓ Accepted answer

For first, put the local script in StarterGui or StarterPlayerScripts and try to find the part with location (example: workspace.Part)

Why put this in StarterGui? local scripts only works in PlayerGui,StarterPlayerScript,StarterPack and others.

Here is the fixed script:

-- StarterGui --
local brick = workspace.Part -- Location of brick
local click = brick:WaitForChild("ClickDetector") -- Location of click detector

-- Function to destroy.
click.MouseHoverEnter:Connect(function() -- you dont need to get player here. you can use game.Players.LocalPlayer in local scripts.
	brick:Destroy()
	wait(1) -- For no errors.
end)

Hope it helped :)

Errors? tell-me on comments.

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