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)
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)
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