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

How to enable a specific players gui?

So i have this script that goes inside my bullet, its simple, the bullets name is the player that shot it name. and the way it gets the correct player to enable the gui is that it tostrings bullet name and just do game.Players.(name).PlayerGui.ScreenGui.Visible = true. but when it attempts that it says attempt to index nil with screengui. how can i fix this? also the script is a normal script, not a local


function ont (hit)
	if hit.Parent.Name ~= (script.Parent.Name) then
		local humanoid = hit.Parent:findFirstChild("Humanoid")
		if humanoid ~= nil then
			local name = tostring(script.Parent.Name)
			script.Parent = workspace
			print("got hit")
			wait(0.2)
			
			--if humanoid.Health >= 1 then
			print("humanoid died")
				game.Players.name.PlayerGui.ScreenGui.Enabled=true
				wait(1)
			game.Players.name.PlayerGui.ScreenGui.Enabled=false
			--end
			
		end
	end
end
script.Parent.Touched:connect(ont)

2 answers

✓ Accepted answer

You cannot access the player's PlayerGui from the server. You will need to use a RemoteEvent to communicate with the client.

Very simple example of how to set it up...

-- Server
local PlayerGuiRemote = game.ReplicatedStorage.PlayerGuiRemote

script.Parent.Touched:Connect(function(object)
	local player = ...
	PlayerGuiRemote:FireClient(player, "ScreenGui", true) -- tell the player the UI, and whether or not to enable it
end)

--------------------------------------------------------------------------------

-- Client
local PlayerGuiRemote = game.ReplicatedStorage:WaitForChild("PlayerGuiRemote")
local LocalPlayer = game.Players.LocalPlayer

PlayerGuiRemote.OnClientEvent:Connect(function(ui, toggle)
	LocalPlayer.PlayerGui[ui].Enabled = toggle
end)

1 comment

0

forgot about that detail, yeah

You should use Players[name] instead of Players.name, because the second one is seen as Players["name"] which is not what you're looking for. So for example:

game.Players[name].PlayerGui.ScreenGui.Enabled = true

1 comment

0

You can fire a server event in replicated storage that fires a local script in StarterPlayerGui, which can enable the gui.

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