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

PlayerGui not working with findfirstchild?




local mouse = game.Players.LocalPlayer:GetMouse()
local players = game:GetService("Players")


...
	local target = mouse.Target
	local humanoid = target.Parent:FindFirstChild("Humanoid")
	print("Hello")
	if humanoid then
		print("Humanoid trovato bae")
		local character = humanoid.Parent
		local nomeplayer = players:GetPlayerFromCharacter(character)
        print(nomeplayer)
        local playergui = nomeplayer:FindFirstChild("Playergui")
        print(playergui)
	end
end
end)

I tried to get a player with my mouse, check if he is a humanoid, then I got his name and now I wanted to get into his playergui, It gave me NIL as print(playergui) so I tried to change "PlayerGui" to BackPack and it worked. Can you help me?

3 answers

Hi. Another player's PlayerGui cannot be accessed by local code.

There is no such thing as "Playergui", capitalization matters in Lua so it's actually "PlayerGui".

And you should flip the mouse and player variables then in the mouse variable just do "local Mouse = players:GetMouse()"

Also, you cannot access the PlayerGui using code, you would have to fire to the client then access it and do whatever code you want to do there.

4 comments

0

Might you please help me doing this? I'm not that good in Remote Events.

0

Sure! In your game add a RemoteEvent in ReplicatedStorage then in the script locate it "local event = game.ReplicatedStorage.RemoteEvent" then in your script where you put print(playergui) do "event:FireClient(player)" then in a local script do the event.OnClientEvent function with your code inside (accept answer if this was helpful)

0

Alright, look at my answer.

0

I've posted the script here, please help me, it gives me Argument 1 missing error

Alright.

I put a RemoteEvent in replicatedstorage. Then, I put a localscript in StarterGui where I wrote the following code:

local event = game.ReplicatedStorage.RemoteEvent
local players = game:GetService("Players")
local mouse = game.Players.LocalPlayers:GetMouse()
local event = game.ReplicatedStorage.RemoteEvent

event.OnClientEvent:Connect(function(plr)
	local target = mouse.Target
	local humanoid = target.Parent:FindFirstChild("Humanoid")
	print("Hello")
	if humanoid then
		print("Humanoid trovato bae")
		local character = humanoid.Parent
		local nomeplayer = players:GetPlayerFromCharacter(character)
        print(nomeplayer)
        local playergui = nomeplayer:FindFirstChild("Playergui")
        print(playergui)
	end
end)

And then, I put another localscript in StarterGui.ScreenGui which says:

local players = game:GetService("Players")
local mouse = game.Players.LocalPlayer:GetMouse()
local event = game.ReplicatedStorage.RemoteEvent

mouse.KeyDown:connect(function(k)
k = k:lower()
if k == 'z' then
     game.ReplicatedStorage.RemoteEvent:FireClient()
end
end)


And yes, I know keydown is deprecated. But just help me.

3 comments

0

You cannot fire to the client in a local script that makes no sense, you should change the OnClientEvent code to a sever script and put that into ServerScriptService and then switch "OnClientEvent" to OnServerEvent

0

Still not working...

0

game.ReplicatedStorage.RemoveEvent:FireClone() - ERROR: Argument 1 missing or nil

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