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)
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.
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. ↩
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)