Converting LocalScript into Script

How would I convert this LocalScript…

local tool = game.Players.LocalPlayer.Backpack.DefaultPillow

local character = game.Players.LocalPlayer.Character


print("The pillow was equipped.")

tool.Parent.DefaultPillowAccessory.Handle.Transparency = 1 --The tool's parent is the character, where the accessory is, and I can access it from there.



print("The pillow was unequipped.")

character.DefaultPillowAccessory.Handle.Transparency = 0--Grabbing the accessory from the character since the tool is now in Backpack and not in the character


…into a normal script?

More information: The LocalScript is located in StarterCharacterScripts. Its purpose is to make the handle of an accessory disappear when you equip a certain tool, and reappear when you unequip the certain tool. The problem is that the accessory disappears only on the client, and not the server, so it stays visible when another player does it.

Cant you just copy the whole code and paste it in a server script? Just insert a server script in StarterCharacterScripts, and then paste the code inside of it, and remove the local script

Edit: Never mind , my bad

I tried that, and I got this error:

16:25:10.386 Workspace.SpeakerDev.AccessoryRemover:1: attempt to index nil with 'Backpack' - Server - AccessoryRemover:1

Are you not able to fire a remote event from the local script saying to make the pillow visible/invisible?

-- DefaultPillowSignaler.client.lua (or something)
-- in StarterCharacterScripts

local pillowEquippedRemote = -- remote event in replicated storage


-- DefaultPillowReplicator.server.lua (or something)
-- in ServerScriptService

local pillowEquippedRemote = -- same remote event

pillowEquippedRemote.OnClientEvent:Connect(function(player, isVisible)
    local character = player.Character
    if not character then return end

    character.DefaultPillowAccessory.Handle.Transparency = isVisible and 0 or 1

Edit: fixed a typo on the .OnClientEvent connection

Oh wait I see what’s the problem.
Try using the following code inside your server script (should be inside of StarterCharacterScripts):

local character = script.Parent -- The script will directly go inside the character

character.ChildAdded:Connect(function(Tool) -- When an instance is added inside the character
   if Tool:IsA("Tool") and Tool.Name == "DefaultPillow" then -- if the instance that was added is a tool and the name is 'DefaultPillow'
      print("The pillow was equipped")
      character.DefaultPillowAccessory.Handle.Transparency = 1

character.ChildRemoved:Connect(function(Tool) -- When an instance is removed
   if Tool:IsA("Tool") and Tool.Name == "DefaultPillow" then -- Again if the instance that was removed was a tool and the name is 'DefaultPillow'
      print("The pillow was unequipped")
      character.DefaultPillowAccessory.Handle.Transparency = 0
1 Like

When your on the server you can’t get local player (There is none!) so you have to use a remote event.
Edit: use the code above the one above this (I was too slow lol)