Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 7 years ago
Edited 7 years ago

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)
1
Only 3 lines but it says it has 112 gg TheUniPiggy 77 — 7y
0
Hopefully this isn't the right script... Becuase your error is happening on line 112 and this one only had 3. xXLegendarySoldierXx 129 — 7y
0
Line 2 is line 112. GatitosMansion 187 — 7y
0
This should be a local script in ReplicatedFirst? TheUniPiggy 77 — 7y
View all comments (2 more)
0
This script is in server script service GatitosMansion 187 — 7y
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. tkcmdr 341 — 7y

2 answers

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
7 years ago

Script objects should not be peeking into the PlayerGui. With FilteringEnabled, the server doesn't even have access to GUIs1.

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. 

0
My game does not have filtering enabled, so why does it not work? GatitosMansion 187 — 7y
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? GatitosMansion 187 — 7y
Ad
Log in to vote
1
Answered by
Azarth 3141 Moderation Voter Community Moderator
7 years ago

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)

Answer this question