#What did I do wrong here to get this error msg? (could be a lot)

1 messages · Page 1 of 1 (latest)

brave coral
#

I dont know why im getting this erorr msg, tryin to do data save stuff

#

part of script where error msg is coming from

mossy meteor
#

I might be very wrong, but i assume gui will be nil, since it can't find PlayerGui, since its deleted?
But to be honestly, thats pretty bad approach.

brave coral
#

I dont think so cuz a dif script that uses PlayerRemoving and PlayerGui works

#

but ur prob right about the Gui being nil just dont know how to fix

mossy meteor
#
  02:33:41.077  Disconnect from 127.0.0.1|60746  -  Studio
  02:33:41.079  nil  -  Server - Script:6
  02:33:41.080  ServerScriptService.Script:7: attempt to index nil with 'FindFirstChild'  -  Server - Script:7
players.PlayerRemoving:Connect(function(ply: Player)
    local gui = ply:FindFirstChild("PlayerGui")
    print(gui)
    local Inv = gui:FindFirstChild("InventoryScreen")
    print(Inv)
    local Frame = Inv:FindFirstChild("InventoryFrame")
    print(Frame)
    local Label = Frame:FindFirstChild("InventoryText")
    print(Label)
    local tex = Label.Text
    print(tex)
end)

So yes, the gui will be deleted first than trigger the PlayerRemoving

brave coral
#

I swtiched player:findfirstchild("PLayerGui") to player.PlayerGui and got a dif error msg saying "playergui is not a valid member ot my player"

mossy meteor
#

Yea, i think maybe youre "lucky" enough, to catch it, before it getting deleted.

But as i said, this isn't the best approch.

I would create a Player table for it. And if player edit the text, or idk what this is, then save it to Server Player table.

brave coral
#

im beginner idk what a player table is 🙏

frosty spruce
#

waitforchild

mossy meteor
#

THIS IS NOT BEST APPROACH!!!
But this is just a template, showing what kind of Player table is.

local playerData = {}

game.Players.PlayerAdded:Connect(function(ply)
  playerData[ply.UserId] = {
    speed = 0 -- idk what you need
  }

  local textValue = ply:WaitForChild("PlayerGui"):WaitForChild("thistext")
  textValue.Changed:Connect(function()
    playerData[ply.UserId].speed = textValue.Text
  end)

end)

brave coral
mossy meteor
# frosty spruce who's table?

Im bit confused by your question?
Its just a normal table which is pretty good to use also for Player Table. (I would do of course different ways, but showing small things, how things works)