Issue with Food Tool Animation and Gamepass Script

Hello Roblox Scripting Community,

I’m encountering an issue with a food tool in my game, and I’m seeking some help and guidance from fellow scripters. Here’s the problem I’m facing:

I initially created a food tool (a cake) for my game, which was working perfectly. The tool had animations and sounds, and it functioned as expected even when placed in StarterPack. I want to mention that the tool is tied to a gamepass, and that my game was flagged for having alcohol content without age restrictions, which was unintentional.

In response, I removed all alcohol-related tools from my game so I could still entertain a younger audience. To replace one of the gamepass items (an alcohol tool), I introduced a new tool called “Icing,” which the cake tool I mentioned previously. Before making any changes to the gamepass script, the cake tool was functioning correctly – players could hold it and click to eat it.

The issue arose when I updated the gamepass script from “BigBottle” (the name of the previous alcohol tool) to “Icing” (the name of the cake tool). After this change, the cake tool stopped working properly. Players could only hold the cake, and clicking to eat it did not work.

In the Studio Output, I received the error message: “Eat is not a valid member of Tool “Players.Vovix.Backpack.Icing” - Client - Eat Function:6.” However, “Eat” is a valid member of the Icing tool, so I’m puzzled by this error.

Here’s the gamepass script in ServerScriptService that gives players the cake:

local ServerStorage = game:GetService("ServerStorage")
local MarketplaceService = game:GetService("MarketplaceService")
local GamepassID_IcingDonation = 227840061 

game.Players.PlayerAdded:Connect(function(player)
	local function giveToolToPlayer()
		local icingTool = ServerStorage:FindFirstChild("Icing") 

		if icingTool and MarketplaceService:UserOwnsGamePassAsync(player.UserId, GamepassID_IcingDonation) then
			local toolClone = icingTool:Clone()
			toolClone.Parent = player.Backpack
		end
	end

	player.CharacterAdded:Connect(giveToolToPlayer)

	if player.Character then
		giveToolToPlayer()
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	local backpack = player.Backpack
	local icingTool = backpack:FindFirstChild("Icing")

	if icingTool then
		icingTool:Destroy()
	end
end)

And here’s the script for the cake tool itself:

local player = game:GetService("Players").LocalPlayer
local uis = game:GetService("UserInputService")
local toolName = "Icing" -- Tool name
local eatInputType = Enum.UserInputType.MouseButton1 
local isfinished = true
local soundeat = script.Parent.Eat

local function playAnim(input)
	local character = player.Character
	if character then
		local humanoid = character:FindFirstChild("Humanoid")
		local tool = character:FindFirstChild(toolName)
		if humanoid and tool and input.UserInputType == eatInputType and isfinished then
			local animator = humanoid:FindFirstChild("Animator")
			local animation = tool:FindFirstChild("EatAnimation")
			local track = animator and animator:LoadAnimation(animation)
			if track then
				isfinished = false
				track:Play()
				wait(track.Length/5)
				soundeat:Play()
				track.Stopped:Wait()
				isfinished = true
			end
		end
	end
end

uis.InputBegan:Connect(playAnim)

I would appreciate any insights or suggestions on what might be causing this issue and how to resolve it. It could potentially be something easy and I’m just overthinking it. Thank you in advance for your assistance!

2 Likes

I’m certain the issue has something to do with the gamepass script, but I have no idea what the issue is or how it correlates to the hierarchy message I received from my Output about the sound named “Eat”.

2 Likes

try this

Server:

local Players = game:GetService('Players')
local ServerStorage = game:GetService("ServerStorage")

local MarketplaceService = game:GetService("MarketplaceService")
local GamepassID_IcingDonation = 227840061 

function giveToolToPlayer(player)
	local icingTool = ServerStorage:FindFirstChild("Icing") 
	if icingTool and MarketplaceService:UserOwnsGamePassAsync(player.UserId, GamepassID_IcingDonation) then
		icingTool:Clone().Parent = player.Backpack
	end
end

Players.PlayerAdded:Connect(function(player: Player)
	player.CharacterAdded:Wait()
	if player then
		giveToolToPlayer(player)
	end
end)

Players.PlayerRemoving:Connect(function(player: Player)
	local icingTool = player.Backpack:FindFirstChild("Icing")
	if icingTool then
		icingTool:Destroy()
	end
end)

Tool:

local Tool = script.Parent
local LocalPlayer = game:GetService("Players").LocalPlayer

local isfinished = true

function playAnim(input)
	local character = LocalPlayer.Character
	if character == nil or not isfinished then return end 
	
	local humanoid = character:FindFirstChild("Humanoid")
	
	if humanoid and Tool then
		local animator = humanoid:FindFirstChild("Animator")
		local animation = Tool:FindFirstChild("EatAnimation")
		
		local track = animator and animator:LoadAnimation(animation)
		local EatSound = script.Parent:FindFirstChild("Eat")
		
		if track and EatSound then
			isfinished = false
			track:Play()
			wait(track.Length/5)
			EatSound:Play()
			track.Stopped:Wait()
			isfinished = true
		end
	end
end

Tool.Activated:Connect(playAnim)
4 Likes

Perfect, thank you very much! This worked.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.