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

Why is this script not working in server mode but only in the play solo mode?

I was testing this script below in the play solo mode(F5) in studio and it worked perfectly fine, but when I tested it in the server mode in studio, it did not work. I can't figure this out.

local mouse = game.Players.LocalPlayer:GetMouse()
local gui = script.Parent:FindFirstChild("Gui")

if mouse then
	script.Parent.MouseEnter:connect(function()
		if gui then
			gui.Visible = true
		end
	end)
	script.Parent.MouseLeave:connect(function()
		if gui then
			gui.Visible = false
		end
	end)
end

2 comments

0

make sure the script is a local script

0

Yes, it is.

1 answer

✓ Accepted answer

There are a few errors I see.

Let's start from the top.

1.) You're not using WaitForChild.

####Sometimes the script loads before the items it's trying to access. So on line 2, use WaitForChild.

2.) You don't even need to get the mouse or player.

####You're not using them anywhere in the script, so get rid of them.


3.) You don't need to check if gui exists.

####Now that we're using WaitForChild, it has to exist by the time it gets to that part of the script.


Finished Script,

local gui = script.Parent:WaitForChild("Gui")

script.Parent.MouseEnter:connect(function()
	gui.Visible = true
end)

script.Parent.MouseLeave:connect(function()
	gui.Visible = false
end)
Could be simplified

Good Luck!

If I helped, please don't forget to accept my answer.

2 comments

0

Haha, I just realized that I really didn't need to check for the mouse. Anyways, this really helped and it worked. Thanks!

0

No problem.

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