Try doing local targetui = game.Players:FindFirstChild(target).PlayerGui.ZiaWarn.ZiaWarnMsg. If the error is attempt to index nil with 'PlayerGui', then it means that it can’t find a player which is called target.
Yes. That means there is no player named ‘Target’. You have to input the player’s name 100% correctly (case-sensitive). You can also add an additional check so the script doesn’t break.
script.Parent.MouseButton1Click:connect(function()
local target = game.Players:FindFirstChild(script.Parent.Parent.WarnUserBox.Text)
local reason = script.Parent.Parent.Reason.Text
if not target then
print("Target not found.")
return
end
print("Target found")
local targetui = target.PlayerGui.ZiaWarn.ZiaWarnMsg
targetui.Reason.Text = reason
targetui.ZiaWarnMsg.Visible = true
end)
That is because of the print you have on the first line (edited). It actually couldn’t find the target. Did you make sure to input everything correctly? Otherwise, I have no idea why it doesn’t work.
Also I believe the reason why it’s erroring is cause you’re attempting to find a value of a string inside the Players service, which won’t work
There’s been a post relevant to this I believe, you can check that out or try out this script:
local function GetPlayerFromString(Name)
print(Name)
for _, Player in pairs(game.Players:GetPlayers()) do
print(Player.Name)
if Player.Name:lower() == Name:lower() then
print("Found the target")
return Player
end
end
end
script.Parent.MouseButton1Click:connect(function()
local target = script.Parent.Parent.WarnUserBox.Text
print(typeof(target)) --This would be a string
local reason = script.Parent.Parent.Reason.Text
local TargetPlayer = GetPlayerFromString(target)
print(TargetPlayer)
if TargetPlayer then
local TargetGui = TargetPlayer:WaitForChild("PlayerGui")
TargetGui.Reason.Text = reason
TargetGui.ZiaWarnMsg.Visible = true
print("Warned User.")
else
print("Not a valid name.")
end
end)