Warn script error

That helped a bit, but im now getting this error:

Players.Ziathrius.PlayerGui.ZiaWarn.WarnUI.Warn.WarnScript:20: attempt to index nil with ‘PlayerGui’

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)

Its now saying it found the target and warned them but also saying it couldnt find the target.

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.

I have inputted everything correctly, Ill try to figure it out myself, Thanks for helping with some parts though.

Side note, but connect is deprecated

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)

now im getting: Players.Ziathrius.PlayerGui.ZiaWarn.WarnUI.Warn.WarnScript:31: attempt to index nil with ‘WaitForChild’

Could you try it again? Maybe I messed something up, also added print statements

after adding some prints, i can see that its not finding the target player.

Turns out it was already a target. Just ignore my post.

What do you mean? He referenced it at the start of the function:

Also, could you check to see what the output prints?

can you maybe just add a print(target) after defining target? As in, printing the text.

here’s the output:

16:26:42.643 string - Server - WarnScript:28
16:26:42.643 nil - Server - WarnScript:32
16:26:42.643 Username - Server - WarnScript:33
16:26:42.643 Not a valid name. - Server - WarnScript:41

Here is evidence that it isnt me typing my name wrong

Could you try the edited script again? Now we’re just attempting to debug it as this point here :thinking:

16:35:35.476 Nane is not a valid member of Player “Players.Ziathrius” - Server - WarnScript:19
16:35:35.476 Stack Begin - Studio
16:35:35.476 Script ‘Players.Ziathrius.PlayerGui.ZiaWarn.WarnUI.Warn.WarnScript’, Line 19 - function GetPlayerFromString - Studio - WarnScript:19
16:35:35.476 Script ‘Players.Ziathrius.PlayerGui.ZiaWarn.WarnUI.Warn.WarnScript’, Line 33 - Studio - WarnScript:33
16:35:35.476 Stack End - Studio

Oh my gosh I mistyped the variable

Ok try again LOL

I see. it were to seem, lol, lemme retry it

Can you show us the script again? How it looks like?