Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Am I misunderstanding get player from character somehow?

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

4 comments

0

Can you make more detailed script?

0

Remember that when you make a gui in starter gui. The location of the gui moves from starter gui to players.localplayer

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.

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.

2 answers

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

4 comments

0

I hope this helped!

0

This is exactly the same line of code minus the IsA() check that got thrown in after the error occurred

0

When you use :GetPlayerFromCharacter() it returns a Player, no :IsA() needed, try it.

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.

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.