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

In output it says "ServerScriptService.Script:112: attempt to index a nil value"...?

In output it says "ServerScriptService.Script:112: attempt to index a nil value" when I play in a normal server, but when I play in Roblox Studio solo everything works fine. Why is this happening? Thanks!

game.Players.PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(character)
		player.PlayerGui.ScreenGui.JumpPowerTextButton.MouseEnter:connect(function()
			TextLabel.Position = UDim2.new(0, player:GetMouse().X, 0, player:GetMouse().Y) -- Line 112
		end)
	end)
end)

6 comments

1

Only 3 lines but it says it has 112 gg

0

Hopefully this isn't the right script... Becuase your error is happening on line 112 and this one only had 3.

0

Line 2 is line 112.

0

This should be a local script in ReplicatedFirst?

0

This script is in server script service

0

It may be that this script is attempting to index the ScreenGui before it has loaded. Use WaitForChild on the ScreenGui and get back to me.

2 answers

✓ Accepted answer

Script objects should not be peeking into the PlayerGui. With FilteringEnabled, the server doesn't even have access to GUIs[^1].

GUIs should be managed locally by LocalScripts.

[^1]: no access to GUIs not created explicitly by a server script (and doing so is dubiously useful). In particular, GUIs in StarterGui that are copied in won't be accessible by a Script.

2 comments

0

My game does not have filtering enabled, so why does it not work?

0

I figured out what is causing it. It is player:GetMouse().X or Y. I think I am suppose to wait for the mouse or something, so how do I do that?

To basically add to what BT is saying~

GUI's should be referenced from a LocalScript, not a Server script. You need to access your mouse and GUI which will be a lot easier without RemoteEvents to access Local things and trying to find and wait for the GUI in other scripts. Also, as long as you have the StarterGui reset on death (default), it'll do the same thing you're trying to accomplish with PlayerAdded and CharacterAdded.

So, to make it easy on yourself, you should insert a ScreenGui into your StarterGui, then a TextButton, then a LocalScript and write your code in there.

local player = game.Players.LocalPlayer
local ScreenGui = script.Parent
local button = ScreenGui:WaitForChild('TextButton')
local mouse = player:GetMouse()


-- This will center the Button on your mouse
local difx = button.Size.X.Offset/2 
local dify = button.Size.Y.Offset/2

mouse.Move:connect(function()
	button.Position = UDim2.new(0,mouse.X - difx,0,mouse.Y - dify)
end)

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