How do I find the player's PlayerGui with a tool?

Hello! I’m trying to find the players’ gui with a Script since I’m making a simulator game.
I’ve been trying to find what causing the issue but it always says Players.PLAYERNAME.Backpack.Fries.Script:8: attempt to index nil with ‘Parent’
(My grammar might be bad I’m not a national speaker)

local tool = script.Parent
local anim ="Animation")
anim.AnimationId = "rbxassetid://ID"
local track
local player = game:GetService("Players")

	local plr = player:GetPlayerFromCharacter(plr.Parent.Parent.Parent)
	if plr then
		local bool = plr.PlayerGui.GUI.fri.bool
		local newbool = bool.Value + 20
		bool.Value = newbool
		plr.Character:ScaleTo(math.floor(bool.Value / 12))
	script.Enabled = false
	tool.Enabled = false
	track = script.Parent.Parent.Humanoid:LoadAnimation(anim)
	track.Priority = Enum.AnimationPriority.Action
	script.Parent.Handle.Eat.Enabled = true
	script.Parent.Handle.Eat.Enabled = false
	script.Enabled = true
	tool.Enabled = true


should be:

local plr = player:GetPlayerFromCharacter(plr.Character)

since the character is parented to the player.

The character is not parented to the player, it is parented to the workspace.

I think what you meant to say was Character is a property of the player?

1 Like

This is causing an error, since you added plr as a parameter, and a tool activation does not give the player as a parameter. You could do something like this:

local players = game:GetService("Players")

    local plr = players:GetPlayerFromCharacter(tool.Parent)

as when the tool is activated it will be parented to the player’s character. Or, just manage it all from one server script for simplification and less memory usage.

(you should move this to #help-and-feedback:scripting-support)