Well all I want is this tool to destroy itself after one use. Apparently that's quite the challenge for me it really shouldn't be. Regardless, the output prints Players.NexusCoil.Backpack.Apple.Eat:25: attempt to index upvalue 'p' (a nil value) Which I assume means it doesn't find the player? This is in a normal script just inside of the tool. Here is the code although the error seems to be connected to lines 2 and well 25.
local Tool = script.Parent;
local p = game.Players:GetPlayerFromCharacter(Tool.Parent)
enabled = true
function onActivated()
if not enabled then
return
end
enabled = false
Tool.GripForward = Vector3.new(-0.97, 1.02e-005, -0.243)
Tool.GripPos = Vector3.new(-0.2, 0, -1.23)
Tool.GripRight = Vector3.new(0.197, 0.581, -0.79)
Tool.GripUp = Vector3.new(-0.141, 0.814, 0.563)
Tool.Handle.EatSound:Play()
wait(.8)
local h = p.PlayerGui.HandT:FindFirstChild("Hunger")
if (h ~= nil) then
if (h.Value + 30 > 100) then
h.Value = h.Value + 30
Tool:Destroy()
else
h.Value = 100
Tool:Destroy()
end
end
Tool.GripForward = Vector3.new(-1, 0, -0)
Tool.GripPos = Vector3.new(0.2, 0, 0)
Tool.GripRight = Vector3.new(0,0, -1)
Tool.GripUp = Vector3.new(0,1,0)
enabled = true
Tool:Destroy()
end
script.Parent.Activated:connect(onActivated)
