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

PlayerGui not working with findfirstchild?

Asked by 5 years ago



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

Log in to vote
0
Answered by 5 years ago

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

Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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.

0
Might you please help me doing this? I'm not that good in Remote Events. Fixer1987 95 — 5y
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) YabaDabaD0O 505 — 5y
0
Alright, look at my answer. Fixer1987 95 — 5y
0
I've posted the script here, please help me, it gives me Argument 1 missing error Fixer1987 95 — 5y
Log in to vote
0
Answered by 5 years ago

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.

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 YabaDabaD0O 505 — 5y
0
Still not working... Fixer1987 95 — 5y
0
game.ReplicatedStorage.RemoveEvent:FireClone() - ERROR: Argument 1 missing or nil Fixer1987 95 — 5y

Answer this question