-- Don't use this as a learning example. It has no serverside verification and
-- is easily exploitable. This is fine for demo purposes, but not live games!

script.Parent.RemoteEvent.OnServerEvent:Connect(function(player, cursorPos)
	local projectile = Instance.new("Part")
	projectile.Size = Vector3.new(0.5, 0.5, 0.5)
	projectile.Material = "Neon"
	projectile.BrickColor = BrickColor.new("Neon orange")
	projectile.Transparency = 0.5
	projectile.Shape = Enum.PartType.Ball
	projectile.CFrame = tool.Handle.CFrame
	
	local attachment = Instance.new("Attachment", projectile)
	
	local vectorForce = Instance.new("VectorForce", projectile)
	vectorForce.RelativeTo = Enum.ActuatorRelativeTo.World
	vectorForce.Attachment0 = attachment
	vectorForce.Force = (cursorPos - tool.Handle.CFrame.p).unit * PROJECTILE_FORCE
	
	projectile.Parent = workspace
	projectile:SetNetworkOwner(player)
	Debris:AddItem(projectile, 5)
	
	projectile.Touched:Connect(function()
		projectile:Destroy()
	end)
end)
