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
	local tCharacter = Tool.Parent
	if game.Players:GetPlayerFromCharacter(tCharacter) then
		Character = tCharacter
		Humanoid = Character:FindFirstChildOfClass("Humanoid")

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)
		Handle.ClosedCover.Transparency = 1
		Handle.OpenCover.Transparency = 0		
		CanOpened = true
		Busy = false

	Busy = true
	MaxUses -= 1
	if MaxUses <= 0 then 

		local TossAnim = Humanoid:LoadAnimation(TossAnimation) -- throwing away the can
		Handle.Transparency = 1
		Handle.OpenCover.Transparency = 1	
		Handle.Beans.Transparency = 1	
		local Can = game.ReplicatedStorage.DetailStuff.Cans.CanBeans:Clone()
		Can.Position = Handle.Position
		Can.Parent = workspace	

		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
		Player.Character.LeftHand.Spoon.Transparency = 0	
		Hunger.Value = math.clamp(Hunger.Value + HungerPerUse, 0, MaxHunger) -- first spoonful
		Hunger.Value = math.clamp(Hunger.Value + HungerPerUse, 0, MaxHunger) -- second spoonful
		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

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!