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?
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.
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.