What I want to happen is when one player kills another player, a GUI to appear on the killer’s screen that says “you killed (victim).” I have the code written, and I found that the script knows who killed who by print debugging (based off the creator tag from classic roblox weapons). The problem is, the script for some reason doesn’t think that PlayerGui exists! When the script runs and the victim dies, it errors: "PlayerGui is not a valid member of Player “Players.(victim)” ". The way that I am making the GUI appear is by cloning a frame from ReplicatedStorage into a specific ScreenGui inside of the killer’s PlayerGui named “KillNotify”.
I would like to know why I’m getting that error, and a possible fix please!
Here’s my code, it’s a local script located inside of KillNotify:
local plr = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
game:GetService('Players').LocalPlayer:WaitForChild('PlayerGui')
hum.Died:Connect(function()
local killer = hum:FindFirstChild("creator").Value
--print(killer.ClassName)
--print("found killer "..killer.Value)
local gui = game.ReplicatedStorage.YouKilledGui:Clone()
gui.Parent = killer.PlayerGui.KillNotify
gui.TextLabel.Text = "You Killed: "..hum.Parent.Name
gui.Visible = true
gui.TextLabel.Visible = true
wait(10)
gui.Visible = false
gui.TextLabel.Visible = false
gui:ClearAllChildren()
gui:Destroy()
--end
end)