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

Getting access to a player gui without their name?

Alright, I've done this to get the player's name.

local m = game.Players.LocalPlayer:GetMouse()
local ErasureActive = game.ReplicatedStorage.ErasureActive.Value
local ttime = "ok"

m.KeyDown:connect(function(k)
k = k:lower()
if k == 'z' then 
 if ttime == "ok" then
  local target = game.Players.LocalPlayer:GetMouse().Target
  local h = target.Parent:FindFirstChild('Humanoid')
  if h then
	local player = print(h.Parent.Name)
	local playerfind = player
end
end
end
end)

Now I'd like to get access to his PlayerGui, so I tried

game.Players{playerfind}.PlayerGui.Erasure.Z.Disabled = true

The output says:

Trying to call method on object of type: Players with incorrect arguments. Help, please?

1 comment

0

Are you using remote events? Also, are you making a My Hero Academia-based game? Lol.

2 answers

local player = game.Players:GetPlayerFromCharacter(target.Parent)
local pgui = player.PlayerGui

2 comments

0

Still giving me "nil" problem.

0

well if you have filtering enabled on you cant access someone elses playergui like that. you need a remote event

Hi Fixer,

I'm very confused what the objective of your script is. Your script looks very inefficient and you're not making complete use of your variables. You can easily get the player using :GetPlayerFromCharacter(). Also, don't use KeyDown, it's deprecated. Use UserInputService instead.

####Here's how I'd get the player's PlayerGui:

local uis = game:GetService("UserInputService");
local players = game:GetService("Players");
local player = players.LocalPlayer;
local mouse = player:GetMouse();

function return_hit()
	local target = mouse.Target;
	local hum = target.Parent:FindFirstChild("Humanoid") or target.Parent.Parent:FindFirstChild("Humanoid");
	if hum then
		local char = hum.Parent;
		local other_player = players:GetPlayerFromCharacter(char);
		return other_player;
	end
end

function detect_key(obj, gp)
	if obj.KeyCode == Enum.KeyCode.Z and not gp then
		local targeted_player = return_hit();
		
		if not targeted_player return end

		local plr_gui = targeted_player:WaitForChild("PlayerGui");

		-- Do whatever you want with the player gui of the targeted player.
	end
end

##Well, I hope I helped and have a wonderful day/night.

Thanks,

Best regards,

~~ KingLoneCat

1 comment

0

Not working though.

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