Why does this tool only work if it starts in starter pack?

I am trying to make a stew that the player can eat.

The problem is that if the tool starts in StarterPack it works but if it starts in ReplicatedStorage, it dosent. I have no idea why.

Here is the local script parented to the tool:

local Player = game:GetService("Players").LocalPlayer
local Character = Player.CharacterAdded:Wait()

local Animations = script.Parent.Animations

local HoldStewAnimation = Character:WaitForChild("Humanoid"):LoadAnimation(Animations.HoldStew)
HoldStewAnimation.Looped = true

local DrinkStewAnimation = Character:WaitForChild("Humanoid"):LoadAnimation(Animations.DrinkStew)
DrinkStewAnimation.Looped = false

script.Parent.Activated:Connect(function()
	script.Parent.Handle.Slurp:Play()
	DrinkStewAnimation:Play()
	DrinkStewAnimation.Ended:Wait()
	task.wait(0.3)
	script.Parent.DrinkStew:FireServer()
	HoldStewAnimation:Stop()
	script.Parent:Destroy()
end)

script.Parent.Equipped:Connect(function()
	HoldStewAnimation:Play()
end)

script.Parent.Unequipped:Connect(function()
	HoldStewAnimation:Stop()
end)

Their is also a server script in the tool that changes gives the player hunger back:

script.Parent.DrinkStew.OnServerEvent:Connect(function(Player)
	Player.Character.Hunger.Value = Player.Character.Hunger.Value + 800
	if Player.Character.Hunger.Value > 1200 then
		Player.Character.Hunger.Value = 1200
	end
end)

It doesnt work in ReplicatedStorage because when you give the tool to the player

this line will wait for a new character to be added.
replace that line with this:

local Character = Player.Chracter or Player.CharacterAdded:Wait()
1 Like

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