What does this error mean?

DrinkSound is not a valid member of LocalScript “Players.Auevi.Backpack.Coffee.LocalScript”

-- Services
local Players = game:GetService('Players')

-- Accessing the local player
local Player = Players.LocalPlayer

local tool = script.Parent
local drink_sound = script.DrinkSound
local clicked = false
tool.Activated:Connect(function()
	if clicked == false then
		clicked = true
		drink_sound:Play()
		local humanoid = tool.Parent:FindFirstChild("Humanoid")
		humanoid.Health = humanoid.Health + 5
		task.wait (2)

		-- Find tool in StarterGear
		local StarterTool = Player.StarterGear:FindFirstChild(tool.Name)
		if  StarterTool then
			StarterTool:Destroy()
		end
		-- Destroy tool in hands
		tool:Destroy()
	end
end)

Screen Shot 2022-07-27 at 1.25.48 PM

script.Parent:WaitForChild("DrinkSound")

Local scripts (that run on the client) may need to wait for instances to load/replicate (on the server).

The script doesn’t contain a ‘DrinkSound’ child instance.

local drink_sound = script.DrinkSound
1 Like

Instead of using script.DrinkSound you need to use script.Parent.DrinkSound since it’s a parent of the tool.

2 Likes