This won't work but there aren't any errors in output

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)

Where is this tool located? In the StarterPack?

This won’t be executable by the server as its referencing things only the client can see. User input can’t be captured by the server either.
What you could do is move all the logic of the eating animation (I assume this is the player eating food?) to the server and have each tool fire a remote event to the server instead. Then the server can respond by animating the player and all that.

i put it in starter pack for ease during testing, but its going to be given from a part from replicated storage later

1 Like

I see. Well, you should take a look at what @MP3Face said, because user input can’t be detected server-side. You should move the input detection to the localscript and then fire a RemoteEvent telling the server to handle animations and all that.

Well I only want some of the details to be server sided, like the can opening and being dropped, as well as the spoons. But I don’t know where to start? I’ve read the roblox guide, but I don’t understand it. Could you write some sample code for me to start at? like one for the local script to send and one for the server script to receive

I don’t have time right now, I’ll do it as soon as I can.

nvm i figured it out myself. it’s actually simple lol

1 Like

That’s great! Have a nice day!