How would I convert this local script into a server script?

This script for me inside of my tool only worked local and cloned the part for the client. I want to be able to make this script clone the part and shoot in the mouse’s direction on a server script, although I dont know how I would fit something like that in my script.

Here is my code

local tool = script.Parent.Parent
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local GamePuck = script.Parent
local bodyForce = Instance.new('BodyForce', GamePuck)

game:GetService("UserInputService").InputBegan:Connect(function(input)
	if(input.UserInputType == Enum.UserInputType.MouseButton1)then
		wait(0.08)
		game.Workspace.GamePuck:Destroy()
		if script.Parent.WeldPuck.Disabled then
			local GamePuck = game.ReplicatedStorage.GamePuck:Clone()
			GamePuck.Parent = workspace
			local antiGravity = Instance.new("BodyForce")
			antiGravity.Force = Vector3.new(0, workspace.Gravity * GamePuck:GetMass(), 0)
			antiGravity.Parent = GamePuck
			workspace.GamePuck.CFrame = script.Parent.Parent.PuckAttract.CFrame
			GamePuck.Script.Disabled = true
			GamePuck.CFrame = CFrame.Angles(0,180,90)
			GamePuck.CFrame = plr.Character.HumanoidRootPart.CFrame * CFrame.new(-3,-2.5,-2)
			GamePuck.CFrame = CFrame.new(GamePuck.Position, mouse.Hit.p) 
			GamePuck.Transparency = 0	
			GamePuck.Velocity = CFrame.new(plr.Character.HumanoidRootPart.Position, mouse.Hit.p).lookVector * 130 
			local VerifyPuck = script.Parent.Parent.PuckAttract.VerifyPuck
			if script.Parent.Parent.PuckAttract.VerifyPuck then
				VerifyPuck:Destroy()
			end
			task.spawn(function()
				script.Disabled = true
				if script.Parent.WeldPuck.Disabled then
					wait(0.2)
					script.Parent.WeldPuck.Enabled = true
				end

				task.spawn(function()
					wait(0.08)
					antiGravity.Name = 'antiGravity'
					antiGravity.Force = Vector3.new(GamePuck:GetMass() * workspace.Gravity == 1, 0)
				end)

				wait(0.2)
				GamePuck.Touched:connect(function(hit)
					antiGravity.Name = 'antiGravity'
					antiGravity.Force = Vector3.new(GamePuck:GetMass() * workspace.Gravity == 196.2, 0)

				end)
			end)
		end
	end
end)

the UserInputService only works on the client, so you should use remote events

for making a tool effect the server you are going to have to fire an event for a server script to make the change on the server side

would i fire the event for cloning the part and getting the mouse?

so from the looks of it you are trying to apply a force on a puck that is cloned from replicated storage so you will need to fire the event with a reference to the puck in replicated storage and then all the things u wanna do to that puck you write in a server script E.G

  • clone the puck
  • parent it to workspace
  • if you want the client to apply a certain force u neeed to send that vector3 to the server as well
  • etc etc

TLDR
send all the necessary information when you fire the event to the server to apply all that information to the puck

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.