Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Am I misunderstanding get player from character somehow?

Asked by 4 years ago

So the issue comes in when I'm trying to store the player into a variable. But for some reason when I go to check that variable immediately after I set it, I get the error that "PlayerGui is not a valid member of Model" which seems odd because if I recall correctly, it's supposed to return the player, not the player's character. Maybe there's something I'm missing. Here's the troublesome piece of code.

if game:GetService("Players"):GetPlayerFromCharacter(targetedCharacter):IsA("Player") then
        print("This is a player")
        local plrCheck = game:GetService("Players"):GetPlayerFromCharacter(targetedCharacter)
        if not plrCheck.PlayerGui:FindFirstChild("CursedGui") then
0
Can you make more detailed script? zuup123 99 — 4y
0
Remember that when you make a gui in starter gui. The location of the gui moves from starter gui to players.localplayer Skydoeskey 108 — 4y
0
The entire script is over 400 lines long and this is specifically where the issue comes in at. There's no outside code that interacts with it aside from the targeted character, which can only ever be a character model. XxTrueDemonxX 362 — 4y
0
The server can see any Gui's that are moved from starterGui and it's not a Gui that's the error. It's the player variable itself that seems to have gone wrong. XxTrueDemonxX 362 — 4y

2 answers

Log in to vote
0
Answered by
zuup123 99
4 years ago
Edited 4 years ago

You're probably trying to find PlayerGui inside a player's character. PlayerGui is located in the player,player is located in the game.Players. Script must be something like this:

if game:GetService("Players"):GetPlayerFromCharacter(targetedCharacter) then
        print("This is a player")
        local plrCheck = game:GetService("Players"):GetPlayerFromCharacter(targetedCharacter)
        if not plrCheck.PlayerGui:FindFirstChild("CursedGui") then
    end
end
0
I hope this helped! zuup123 99 — 4y
0
This is exactly the same line of code minus the IsA() check that got thrown in after the error occurred XxTrueDemonxX 362 — 4y
0
When you use :GetPlayerFromCharacter() it returns a Player, no :IsA() needed, try it. zuup123 99 — 4y
0
As I just said, that was thrown in after the error occurred. Either way, the IsA wouldn't effect it in any way and that's not where the error even occurs. XxTrueDemonxX 362 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

The issue is fixed. I rewrote the function and double checked and it's working now. I probably made a spelling error that I missed though I don't know where as the part where the error occurred is still the same. This question can be closed.

Answer this question