Need help to convert localscript into a script

Hi! I need help in converting this localscript into a normal script:

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local uis = game:GetService("UserInputService")
local movingpart = workspace.Union
local tool = script.Parent
local inputConnection
local isEquipTool = false

script.Parent = game:GetService("Players").LocalPlayer:WaitForChild("PlayerScripts")

uis.InputBegan:Connect(function(input, gameProcessedEvent)
	if not isEquipTool then return end
	if not gameProcessedEvent then return end

	if input.KeyCode == Enum.KeyCode.Left then
		movingpart.Position = movingpart.Position + Vector3.new(0, 0, -1)
		print("Moving part left")
	elseif input.KeyCode == Enum.KeyCode.Right then
		movingpart.Position = movingpart.Position + Vector3.new(0, 0, 1) 
		print("Moving part right")
	end
end)

tool.Equipped:Connect(function()
	isEquipTool = true
end)

tool.Unequipped:Connect(function()
	isEquipTool = false
end)

Converting the whole script to a server script is not doable because it is not possible to get someone’s input on server side and getting LocalPlayer from server is also impossible. However the script can be split into one client script and one server script. I am talking about the content of InputBegan event’s function. You can move it properly to a server script. In this event you should put code responsible for firing a RemoteEvent from client to server. Let me know if something is not clear to you.

Can you explain a bit to me about the RemoteEvent? I’m not a scripter in any way so I don’t know much.

Does that help? Let me know if this is not enough.

Yeah that helps. Thanks for the support!

1 Like