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 = Instance.new("Animation")
anim.AnimationId = "rbxassetid://ID"
local track
local player = game:GetService("Players")

tool.Activated:Connect(function(plr)
	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))
	end
	
	script.Enabled = false
	tool.Enabled = false
	track = script.Parent.Parent.Humanoid:LoadAnimation(anim)
	track.Priority = Enum.AnimationPriority.Action
	track:Play()
	script.Parent.Handle.Eat.Enabled = true
	wait(0.5)
	script.Parent.Handle.Eat.Enabled = false
	wait(2)
	script.Enabled = true
	tool.Enabled = true
end)


2 Likes

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")

tool.Activated:Connect(function()
    local plr = players:GetPlayerFromCharacter(tool.Parent)
end)

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)