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

How to enable a specific players gui?

Asked by 3 years ago

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

Log in to vote
1
Answered by 3 years ago

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)
0
forgot about that detail, yeah LeHelary 142 — 3y
Ad
Log in to vote
0
Answered by
LeHelary 142
3 years ago
Edited 3 years ago

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
0
You can fire a server event in replicated storage that fires a local script in StarterPlayerGui, which can enable the gui. miner561473 17 — 3y

Answer this question