I’m trying to convert this local script to work as a server script so everyone can see it. Somebody suggested I change the local player stuff into Tool.Parent.Parent
. When I changed it, it broke but there weren’t any errors in output.
local MaxUses = 3 -- add one up due to bug
local HungerPerUse = 2
local MaxHunger = 18.1
local Tool = script.Parent
local Player = Tool.Parent.Parent
local Hunger = Player:WaitForChild("HungerVal")
local Handle = Tool:WaitForChild("Handle")
local OpenSound = Tool.Handle:WaitForChild("CanOpen")
local ScoopSound = Tool.Handle:WaitForChild("SpoonScope")
local EatAnimation = Tool:WaitForChild("EatAnim")
local OpenAnimation = Tool:WaitForChild("OpenAnim")
local TossAnimation = Tool:WaitForChild("TossAnim")
local Character = nil
local Humanoid = nil
Tool.Equipped:Connect(function()
local tCharacter = Tool.Parent
if game.Players:GetPlayerFromCharacter(tCharacter) then
Character = tCharacter
Humanoid = Character:FindFirstChildOfClass("Humanoid")
end
end)
local ResetTime = 2 -- cooldown to eating
local isUsed = false -- Declare debounce variable
local CanOpened = false
local Busy = false
Tool.Activated:Connect(function() -- opening the can
if not Character or not Humanoid then Busy = false return end
if Busy then return end
if not CanOpened then
Busy = true
local OpenCanAnim = Humanoid:LoadAnimation(OpenAnimation)
OpenCanAnim:Play()
wait(0.5)
OpenSound:Play()
wait(0.2)
Handle.ClosedCover.Transparency = 1
Handle.OpenCover.Transparency = 0
wait(1)
CanOpened = true
Busy = false
return
end
Busy = true
MaxUses -= 1
if MaxUses <= 0 then
local TossAnim = Humanoid:LoadAnimation(TossAnimation) -- throwing away the can
TossAnim:Play()
wait(0.5)
Handle.Transparency = 1
Handle.OpenCover.Transparency = 1
Handle.Beans.Transparency = 1
Handle.ThrowCan:Play()
local Can = game.ReplicatedStorage.DetailStuff.Cans.CanBeans:Clone()
Can.Position = Handle.Position
Can.Parent = workspace
wait(0.25)
Handle:Destroy()
Tool:Destroy()
print("Tool Destroyed")
return end
if not isUsed then -- Check that debounce variable is not true
isUsed = true -- Set variable to true
local StarterGui = game:GetService("StarterGui")
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false) -- disable inventory
local EatAnim = Humanoid:LoadAnimation(EatAnimation) -- eating the can
EatAnim:Play()
Player.Character.LeftHand.Spoon.Transparency = 0
wait(1)
ScoopSound:Play()
Hunger.Value = math.clamp(Hunger.Value + HungerPerUse, 0, MaxHunger) -- first spoonful
wait(2)
ScoopSound:Play()
wait(0.1)
Hunger.Value = math.clamp(Hunger.Value + HungerPerUse, 0, MaxHunger) -- second spoonful
wait(1.8)
Player.Character.LeftHand.Spoon.Transparency = 1
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, true) -- enable inventory
wait(ResetTime) -- Wait for reset time duration
isUsed = false -- Reset variable to false
Busy = false
end
end)